Skip to content

Commit

Permalink
fix(build): do not use rollup alias (#629)
Browse files Browse the repository at this point in the history
* chore: do not use rollup alias

* chore rollup plugins
  • Loading branch information
dai-shi authored Jan 15, 2023
1 parent 353e997 commit cad437c
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 78 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@
"@babel/preset-env": "^7.20.2",
"@babel/types": "^7.20.7",
"@redux-devtools/extension": "^3.2.4",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.3.0",
"@rollup/plugin-typescript": "^11.0.0",
"@swc/core": "^1.3.26",
"@swc/jest": "^0.2.24",
Expand Down Expand Up @@ -182,7 +182,6 @@
"redux": "^4.2.0",
"rollup": "^3.10.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-terser": "^7.0.2",
"shx": "^0.3.4",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
Expand Down
24 changes: 1 addition & 23 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
const path = require('path')
const alias = require('@rollup/plugin-alias')
const babelPlugin = require('@rollup/plugin-babel')
const resolve = require('@rollup/plugin-node-resolve')
const replace = require('@rollup/plugin-replace')
const terser = require('@rollup/plugin-terser')
const typescript = require('@rollup/plugin-typescript')
const { default: esbuild } = require('rollup-plugin-esbuild')
const { terser } = require('rollup-plugin-terser')
const createBabelConfig = require('./babel.config')

const extensions = ['.js', '.ts', '.tsx']
const { root } = path.parse(process.cwd())
const entries = {
'./vanilla': 'valtio/vanilla',
'./react': 'valtio/react',
'./vanilla/utils': 'valtio/vanilla/utils',
'./react/utils': 'valtio/react/utils',
'../../vanilla': 'valtio/vanilla',
'../../react': 'valtio/react',
}

function external(id) {
return !id.startsWith('.') && !id.startsWith(root)
Expand Down Expand Up @@ -63,7 +54,6 @@ function createESMConfig(input, output) {
output: { file: output, format: 'esm' },
external,
plugins: [
alias({ entries }),
resolve({ extensions }),
replace({
__DEV__: output.endsWith('.mjs')
Expand All @@ -85,7 +75,6 @@ function createCommonJSConfig(input, output) {
output: { file: `${output}.js`, format: 'cjs' },
external,
plugins: [
alias({ entries }),
resolve({ extensions }),
replace({
__DEV__: '(process.env.NODE_ENV!=="production")',
Expand Down Expand Up @@ -127,7 +116,6 @@ function createUMDConfig(input, output, env) {
},
external,
plugins: [
alias({ entries }),
resolve({ extensions }),
replace({
__DEV__: env !== 'production' ? 'true' : 'false',
Expand All @@ -148,16 +136,6 @@ function createSystemConfig(input, output, env) {
},
external,
plugins: [
alias({
entries: {
'./vanilla': 'valtio/vanilla',
'./react': 'valtio/react',
'./vanilla/utils': 'valtio/vanilla/utils',
'./react/utils': 'valtio/react/utils',
'../../vanilla': 'valtio/vanilla',
'../../react': 'valtio/react',
},
}),
resolve({ extensions }),
replace({
__DEV__: env !== 'production' ? 'true' : 'false',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './vanilla'
export * from './react'
export * from 'valtio/vanilla'
export * from 'valtio/react'
4 changes: 2 additions & 2 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
// See: https://github.com/pmndrs/valtio/issues/452
// The following is a workaround until ESM is supported.
import useSyncExternalStoreExports from 'use-sync-external-store/shim'
import { snapshot, subscribe } from './vanilla'
import type { INTERNAL_Snapshot as Snapshot } from './vanilla'
import { snapshot, subscribe } from 'valtio/vanilla'
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'

const { use } = ReactExports
const { useSyncExternalStore } = useSyncExternalStoreExports
Expand Down
2 changes: 1 addition & 1 deletion src/react/utils/useProxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLayoutEffect } from 'react'
import { useSnapshot } from '../../react'
import { useSnapshot } from 'valtio/react'

/**
* useProxy
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './vanilla/utils'
export * from './react/utils'
export * from 'valtio/vanilla/utils'
export * from 'valtio/react/utils'
2 changes: 1 addition & 1 deletion src/vanilla/utils/derive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getVersion, proxy, subscribe } from '../../vanilla'
import { getVersion, proxy, subscribe } from 'valtio/vanilla'

type DeriveGet = <T extends object>(proxyObject: T) => T

Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { snapshot, subscribe } from '../../vanilla'
import { snapshot, subscribe } from 'valtio/vanilla'
import type {} from '@redux-devtools/extension'

// FIXME https://github.com/reduxjs/redux-devtools/issues/1097
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/proxyMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { proxy } from '../../vanilla'
import { proxy } from 'valtio/vanilla'

type KeyValRecord<K, V> = [key: K, value: V]

Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/proxySet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { proxy } from '../../vanilla'
import { proxy } from 'valtio/vanilla'

// properties that we don't want to expose to the end-user
type InternalProxySet<T> = Set<T> & {
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/utils/proxyWithComputed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { proxy, snapshot } from '../../vanilla'
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'
import { proxy, snapshot } from 'valtio/vanilla'
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'

/**
* proxyWithComputed
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/utils/proxyWithHistory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { proxy, ref, snapshot, subscribe } from '../../vanilla'
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'
import { proxy, ref, snapshot, subscribe } from 'valtio/vanilla'
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'

type SnapshotOrUndefined<T> = Snapshot<T> | undefined
type Snapshots<T> = Snapshot<T>[]
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/subscribeKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subscribe } from '../../vanilla'
import { subscribe } from 'valtio/vanilla'

/**
* subscribeKey
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subscribe } from '../../vanilla'
import { subscribe } from 'valtio/vanilla'

type Cleanup = () => void
type WatchGet = <T extends object>(proxyObject: T) => T
Expand Down
55 changes: 19 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1514,13 +1514,6 @@
"@babel/runtime" "^7.20.7"
immutable "^4.2.2"

"@rollup/plugin-alias@^4.0.2":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@rollup/plugin-alias/-/plugin-alias-4.0.2.tgz#fec6c6aff8dd6fce580ae6bc5345084cd702bb62"
integrity sha512-1hv7dBOZZwo3SEupxn4UA2N0EDThqSSS+wI1St1TNTBtOZvUchyIClyHcnDcjjrReTPZ47Faedrhblv4n+T5UQ==
dependencies:
slash "^4.0.0"

"@rollup/plugin-babel@^6.0.3":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-6.0.3.tgz#07ccde15de278c581673034ad6accdb4a153dfeb"
Expand Down Expand Up @@ -1549,6 +1542,15 @@
"@rollup/pluginutils" "^5.0.1"
magic-string "^0.27.0"

"@rollup/plugin-terser@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-terser/-/plugin-terser-0.3.0.tgz#43ee908fed27ed2bc876496fb9aab8033a0566ac"
integrity sha512-mYTkNW9KjOscS/3QWU5LfOKsR3/fAAVDaqcAe2TZ7ng6pN46f+C7FOZbITuIW/neA+PhcjoKl7yMyB3XcmA4gw==
dependencies:
serialize-javascript "^6.0.0"
smob "^0.0.6"
terser "^5.15.1"

"@rollup/plugin-typescript@^11.0.0":
version "11.0.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-11.0.0.tgz#f136272d1df5209daca0cb6f171c574b1d505545"
Expand Down Expand Up @@ -4112,15 +4114,6 @@ jest-watcher@^29.3.1:
jest-util "^29.3.1"
string-length "^4.0.1"

jest-worker@^26.2.1:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.6.2.tgz#7f72cbc4d643c365e27b9fd775f9d0eaa9c7a8ed"
integrity sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==
dependencies:
"@types/node" "*"
merge-stream "^2.0.0"
supports-color "^7.0.0"

jest-worker@^29.3.1:
version "29.3.1"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-29.3.1.tgz#e9462161017a9bb176380d721cab022661da3d6b"
Expand Down Expand Up @@ -4980,16 +4973,6 @@ rollup-plugin-esbuild@^5.0.0:
joycon "^3.1.1"
jsonc-parser "^3.2.0"

rollup-plugin-terser@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d"
integrity sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==
dependencies:
"@babel/code-frame" "^7.10.4"
jest-worker "^26.2.1"
serialize-javascript "^4.0.0"
terser "^5.0.0"

rollup@^3.10.0, rollup@^3.7.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.10.0.tgz#6eb19196d8b3b375ca651cb78261faac48e24cd6"
Expand Down Expand Up @@ -5056,10 +5039,10 @@ semver@^7.3.2, semver@^7.3.5, semver@^7.3.7:
dependencies:
lru-cache "^6.0.0"

serialize-javascript@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"
integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==
serialize-javascript@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8"
integrity sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==
dependencies:
randombytes "^2.1.0"

Expand Down Expand Up @@ -5121,10 +5104,10 @@ slash@^3.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

slash@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7"
integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==
smob@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/smob/-/smob-0.0.6.tgz#09b268fea916158a2781c152044c6155adbb8aa1"
integrity sha512-V21+XeNni+tTyiST1MHsa84AQhT1aFZipzPpOFAVB8DkHzwJyjjAmt9bgwnuZiZWnIbMo2duE29wybxv/7HWUw==

source-map-js@^1.0.2:
version "1.0.2"
Expand Down Expand Up @@ -5266,7 +5249,7 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

supports-color@^7.0.0, supports-color@^7.1.0:
supports-color@^7.1.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
Expand All @@ -5290,7 +5273,7 @@ symbol-tree@^3.2.4:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

terser@^5.0.0:
terser@^5.15.1:
version "5.16.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.1.tgz#5af3bc3d0f24241c7fb2024199d5c461a1075880"
integrity sha512-xvQfyfA1ayT0qdK47zskQgRZeWLoOQ8JQ6mIgRGVNwZKdQMU+5FkCBjmv4QjcrTzyZquRw2FVtlJSRUmMKQslw==
Expand Down

1 comment on commit cad437c

@vercel
Copy link

@vercel vercel bot commented on cad437c Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valtio – ./

valtio.vercel.app
valtio-pmndrs.vercel.app
valtio-git-main-pmndrs.vercel.app
valtio.pmnd.rs

Please sign in to comment.