diff --git a/examples/basic/package.json b/examples/basic/package.json index cc6bc9b9c..033dec484 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -7,12 +7,13 @@ "start": "shuvi start" }, "dependencies": { + "@shuvi/package-esmodule": "workspace:*", "shuvi": "workspace:*" }, "devDependencies": { "@types/node": "^18.6.1", "@types/react": "18.0.9", "@types/react-dom": "18.0.6", - "typescript": "^4.7.4" + "typescript": "^5.5.2" } } diff --git a/examples/basic/src/routes/page.tsx b/examples/basic/src/routes/page.tsx index b00e0b24c..da6f946c3 100644 --- a/examples/basic/src/routes/page.tsx +++ b/examples/basic/src/routes/page.tsx @@ -1,6 +1,14 @@ +import { useEffect } from 'react'; +import esModule from '@shuvi/package-esmodule'; +import { consoleLog } from '@shuvi/package-esmodule/utils'; import styles from './style.css'; const Home = () => { + useEffect(() => { + esModule(`from '@shuvi/package-esmodule'`); + consoleLog(`Hello from '@shuvi/package-esmodule/utils'`); + }, []); + return (

Hello World

diff --git a/examples/basic/tsconfig.json b/examples/basic/tsconfig.json index 7117de208..1a90bcea5 100644 --- a/examples/basic/tsconfig.json +++ b/examples/basic/tsconfig.json @@ -15,7 +15,7 @@ "esModuleInterop": true, "noImplicitThis": true, "module": "esnext", - "moduleResolution": "node16", + "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/examples/package-esmodule/.gitignore b/examples/package-esmodule/.gitignore new file mode 100644 index 000000000..9d36fde44 --- /dev/null +++ b/examples/package-esmodule/.gitignore @@ -0,0 +1,2 @@ +/esm +/lib \ No newline at end of file diff --git a/examples/package-esmodule/README.md b/examples/package-esmodule/README.md new file mode 100644 index 000000000..96f19bf99 --- /dev/null +++ b/examples/package-esmodule/README.md @@ -0,0 +1,10 @@ +This is a simple package that exports an ES module. + +https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_package_json_type_field + +```json +// package.json +{ + "type": "module" +} +``` diff --git a/examples/package-esmodule/package.json b/examples/package-esmodule/package.json new file mode 100644 index 000000000..015eb2f7e --- /dev/null +++ b/examples/package-esmodule/package.json @@ -0,0 +1,34 @@ +{ + "private": true, + "name": "@shuvi/package-esmodule", + "version": "1.0.0", + "type": "module", + "main": "lib/index.js", + "module": "esm/index.js", + "types": "esm/index.d.ts", + "exports": { + ".": { + "import": "./esm/index.js", + "require": "./lib/index.js", + "types": "./esm/index.d.ts" + }, + "./utils": { + "import": "./esm/utils.js", + "require": "./lib/utils.js", + "types": "./esm/utils.d.ts" + } + }, + "files": [ + "lib", + "esm" + ], + "scripts": { + "dev": "run-p watch:*", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", + "prebuild": "rimraf lib esm", + "build": "run-p build:*", + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" + } +} diff --git a/examples/package-esmodule/src/index.ts b/examples/package-esmodule/src/index.ts new file mode 100644 index 000000000..bdf9625d9 --- /dev/null +++ b/examples/package-esmodule/src/index.ts @@ -0,0 +1,5 @@ +import { consoleLog } from './utils.js'; + +export default (data?: string) => { + consoleLog(`Hello from package-esmodule ${data}`); +}; diff --git a/examples/package-esmodule/src/utils.ts b/examples/package-esmodule/src/utils.ts new file mode 100644 index 000000000..7577319e3 --- /dev/null +++ b/examples/package-esmodule/src/utils.ts @@ -0,0 +1,3 @@ +export function consoleLog(data: string) { + console.log(data); +} diff --git a/examples/package-esmodule/tsconfig.build.cjs.json b/examples/package-esmodule/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/examples/package-esmodule/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/examples/package-esmodule/tsconfig.build.esm.json b/examples/package-esmodule/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/examples/package-esmodule/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/examples/package-esmodule/tsconfig.json b/examples/package-esmodule/tsconfig.json new file mode 100644 index 000000000..8aa7d66f6 --- /dev/null +++ b/examples/package-esmodule/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "lib": ["esnext", "DOM"], + }, + "include": ["src"] +} diff --git a/package.json b/package.json index fed48600c..5af592c07 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "typedoc-plugin-markdown": "^3.12.1", "typedoc-plugin-missing-exports": "^0.23.0", "turbo": "1.3.4", - "typescript": "4.8.4" + "typescript": "5.5.2" }, "pnpm": { "peerDependencyRules": { diff --git a/packages/compiler/tsconfig.build.json b/packages/compiler/tsconfig.build.json index e6c47dd03..c453e3989 100644 --- a/packages/compiler/tsconfig.build.json +++ b/packages/compiler/tsconfig.build.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "outDir": "lib", - "module": "commonjs" }, "include": ["src"] } diff --git a/packages/error-overlay/package.json b/packages/error-overlay/package.json index 4c28f5160..18e003daf 100644 --- a/packages/error-overlay/package.json +++ b/packages/error-overlay/package.json @@ -10,12 +10,12 @@ "scripts": { "dev": "run-p watch:*", "watch:iframe": "cross-env NODE_ENV=development rollup -c rollup.config.iframe.js -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "watch:umd": "cross-env NODE_ENV=development rollup -c rollup.config.js -w", "prebuild": "rimraf lib", "build": "pnpm run iframe-prod && run-p build:*", "iframe-prod": "cross-env NODE_ENV=production rollup -c rollup.config.iframe.js", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib", + "build:cjs": "tsc -p tsconfig.build.cjs.json", "build:umd": "cross-env NODE_ENV=production rollup -c rollup.config.js" }, "engines": { diff --git a/packages/error-overlay/rollup.config.iframe.js b/packages/error-overlay/rollup.config.iframe.js index 4515dc435..21ea02420 100644 --- a/packages/error-overlay/rollup.config.iframe.js +++ b/packages/error-overlay/rollup.config.iframe.js @@ -23,7 +23,7 @@ export default { }), resolve({ extensions }), ts({ - tsconfig: path.join('./tsconfig.build.json'), + tsconfig: path.join('./tsconfig.build.rollup.json'), declaration: false }), commonjs({ extensions }) diff --git a/packages/error-overlay/rollup.config.js b/packages/error-overlay/rollup.config.js index ef1bc1d90..409ef1016 100644 --- a/packages/error-overlay/rollup.config.js +++ b/packages/error-overlay/rollup.config.js @@ -31,7 +31,7 @@ export default { }), resolve({ extensions }), ts({ - tsconfig: path.join('./tsconfig.build.json'), + tsconfig: path.join('./tsconfig.build.rollup.json'), declaration: false }), commonjs({ extensions }) diff --git a/packages/error-overlay/tsconfig.build.cjs.json b/packages/error-overlay/tsconfig.build.cjs.json new file mode 100644 index 000000000..2750655f4 --- /dev/null +++ b/packages/error-overlay/tsconfig.build.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "lib": ["esnext", "dom"], + "esModuleInterop": true, + "jsx": "react-jsx", + "outDir": "lib", + }, + "include": ["src"] +} diff --git a/packages/error-overlay/tsconfig.build.json b/packages/error-overlay/tsconfig.build.rollup.json similarity index 82% rename from packages/error-overlay/tsconfig.build.json rename to packages/error-overlay/tsconfig.build.rollup.json index 5d8d193cd..01b459985 100644 --- a/packages/error-overlay/tsconfig.build.json +++ b/packages/error-overlay/tsconfig.build.rollup.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "lib": ["esnext", "dom"], "module": "node16", diff --git a/packages/eslint-plugin-shuvi/tsconfig.json b/packages/eslint-plugin-shuvi/tsconfig.json index 323926c41..d6243bbc4 100644 --- a/packages/eslint-plugin-shuvi/tsconfig.json +++ b/packages/eslint-plugin-shuvi/tsconfig.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "outDir": "lib", - "module": "commonjs", "esModuleInterop": true }, "include": ["src"] diff --git a/packages/hook/package.json b/packages/hook/package.json index 6c166477e..56e9ef07b 100644 --- a/packages/hook/package.json +++ b/packages/hook/package.json @@ -14,12 +14,12 @@ }, "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "author": "Zheng Yu Tay" } diff --git a/packages/hook/src/hookGroup.ts b/packages/hook/src/hookGroup.ts index 478322eab..525a94f87 100644 --- a/packages/hook/src/hookGroup.ts +++ b/packages/hook/src/hookGroup.ts @@ -136,7 +136,7 @@ export const createHookManager = ( if (!_hookHandlers[hookName]) { _hookHandlers[hookName] = []; } - _hookHandlers[hookName].push(handlers[hookName]); + _hookHandlers[hookName]!.push(handlers[hookName]); } }); }; diff --git a/packages/hook/tsconfig.build.cjs.json b/packages/hook/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/packages/hook/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/packages/hook/tsconfig.build.esm.json b/packages/hook/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/packages/hook/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/packages/hook/tsconfig.build.json b/packages/hook/tsconfig.build.json deleted file mode 100644 index 563dd0109..000000000 --- a/packages/hook/tsconfig.build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "rootDir": "./src", - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ] -} diff --git a/packages/platform-shared/tsconfig.build.browser.json b/packages/platform-shared/tsconfig.build.browser.json index fcd59ae08..2a1386503 100644 --- a/packages/platform-shared/tsconfig.build.browser.json +++ b/packages/platform-shared/tsconfig.build.browser.json @@ -1,9 +1,8 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.esm.json", "compilerOptions": { "lib": ["esnext", "DOM"], "esModuleInterop": false, - "module": "esnext", "rootDir": "./src", "outDir": "esm" }, diff --git a/packages/platform-shared/tsconfig.build.node.json b/packages/platform-shared/tsconfig.build.node.json index bb25ccd00..0868107f7 100644 --- a/packages/platform-shared/tsconfig.build.node.json +++ b/packages/platform-shared/tsconfig.build.node.json @@ -1,9 +1,8 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "lib": ["esnext", "DOM"], "esModuleInterop": true, - "module": "commonjs", "rootDir": "./src", "outDir": "lib" }, diff --git a/packages/platform-web/tsconfig.build.browser.json b/packages/platform-web/tsconfig.build.browser.json index 1d9dcf43f..ce86e90e4 100644 --- a/packages/platform-web/tsconfig.build.browser.json +++ b/packages/platform-web/tsconfig.build.browser.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.esm.json", "compilerOptions": { "lib": ["esnext", "DOM"], "esModuleInterop": false, "jsx": "preserve", - "module": "esnext", "rootDir": "./src", "outDir": "esm" }, diff --git a/packages/platform-web/tsconfig.build.node.json b/packages/platform-web/tsconfig.build.node.json index 83034de0e..eeda0e9ed 100644 --- a/packages/platform-web/tsconfig.build.node.json +++ b/packages/platform-web/tsconfig.build.node.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "lib": ["esnext", "DOM"], "esModuleInterop": true, "outDir": "lib", - "module": "commonjs", "rootDir": "./src" }, "include": ["src/node"] diff --git a/packages/reporters/package.json b/packages/reporters/package.json index 321065599..547f3eaa9 100644 --- a/packages/reporters/package.json +++ b/packages/reporters/package.json @@ -8,9 +8,9 @@ "lib" ], "scripts": { - "dev": "tsc -p tsconfig.build.json -m commonjs -w", + "dev": "tsc -p tsconfig.build.json -w", "prebuild": "rimraf lib", - "build": "tsc -p tsconfig.build.json -m commonjs" + "build": "tsc -p tsconfig.build.json" }, "dependencies": { "@shuvi/shared": "1.0.55", diff --git a/packages/reporters/tsconfig.build.json b/packages/reporters/tsconfig.build.json index 281deab84..2062901f7 100644 --- a/packages/reporters/tsconfig.build.json +++ b/packages/reporters/tsconfig.build.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "rootDir": "./src", "outDir": "lib", "lib": ["esnext", "DOM"], - "module": "commonjs", "esModuleInterop": true }, "include": ["src"] diff --git a/packages/router-react/package.json b/packages/router-react/package.json index a389056a5..964a0647c 100644 --- a/packages/router-react/package.json +++ b/packages/router-react/package.json @@ -17,12 +17,12 @@ ], "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "engines": { "node": ">= 16.0.0" diff --git a/packages/router-react/tsconfig.build.cjs.json b/packages/router-react/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/packages/router-react/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/packages/router-react/tsconfig.build.esm.json b/packages/router-react/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/packages/router-react/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/packages/router-react/tsconfig.build.json b/packages/router-react/tsconfig.build.json deleted file mode 100644 index b814ecfc2..000000000 --- a/packages/router-react/tsconfig.build.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ] -} diff --git a/packages/router/package.json b/packages/router/package.json index 7ebbdb4e7..06689e1ef 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -17,12 +17,12 @@ ], "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "engines": { "node": ">= 16.0.0" diff --git a/packages/router/tsconfig.build.cjs.json b/packages/router/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/packages/router/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/packages/router/tsconfig.build.esm.json b/packages/router/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/packages/router/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/packages/router/tsconfig.build.json b/packages/router/tsconfig.build.json deleted file mode 100644 index b814ecfc2..000000000 --- a/packages/router/tsconfig.build.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ] -} diff --git a/packages/runtime/package.json b/packages/runtime/package.json index e7598cd83..10216083b 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -18,12 +18,12 @@ "types": "lib/index.d.ts", "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "dependencies": { "@shuvi/hook": "1.0.55" diff --git a/packages/runtime/tsconfig.build.cjs.json b/packages/runtime/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/packages/runtime/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/packages/runtime/tsconfig.build.esm.json b/packages/runtime/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/packages/runtime/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/packages/runtime/tsconfig.build.json b/packages/runtime/tsconfig.build.json deleted file mode 100644 index f32a6a6d7..000000000 --- a/packages/runtime/tsconfig.build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ], - "exclude": ["**/__tests__/**"] -} diff --git a/packages/service/package.json b/packages/service/package.json index 90b62191a..98f148936 100644 --- a/packages/service/package.json +++ b/packages/service/package.json @@ -17,9 +17,9 @@ "types" ], "scripts": { - "dev": "tsc -p tsconfig.build.json -m commonjs -w", + "dev": "tsc -p tsconfig.build.json -w", "prebuild": "rimraf lib", - "build": "tsc -p tsconfig.build.json -m commonjs" + "build": "tsc -p tsconfig.build.json" }, "engines": { "node": ">= 16.0.0" @@ -45,6 +45,7 @@ "http-proxy-middleware": "1.0.6", "rimraf": "3.0.2", "cookie": "0.4.1", + "semver": "7.3.2", "send": "0.17.1", "ws": "8.2.3", "uuid": "9.0.0", @@ -61,6 +62,7 @@ "@types/detect-port": "1.3.0", "@types/cookie": "^0.4.1", "@types/ejs": "3.0.4", + "@types/semver": "7.3.1", "@types/uuid": "^9.0.2", "@types/ws": "8.2.0" } diff --git a/packages/service/src/bundler/typescript/configTypeScript.ts b/packages/service/src/bundler/typescript/configTypeScript.ts index 12e0d9229..6da259f7a 100644 --- a/packages/service/src/bundler/typescript/configTypeScript.ts +++ b/packages/service/src/bundler/typescript/configTypeScript.ts @@ -2,75 +2,132 @@ import chalk from '@shuvi/utils/chalk'; import isEqual from '@shuvi/utils/isEqual'; import fs from 'fs-extra'; import * as CommentJson from 'comment-json'; +import semver from 'semver'; import os from 'os'; import path from 'path'; +import type { CompilerOptions } from 'typescript'; import { IPaths } from '../../core/apiTypes'; import { TypeScriptModule, TsParsedConfig } from './types'; -export async function writeDefaultConfigurations( - ts: TypeScriptModule, - tsConfigPath: string, - tsConfig: TsParsedConfig, - paths: IPaths, - isFirstTimeSetup: boolean -) { - const compilerOptions: any = { - // These are suggested values and will be set when not present in the - // tsconfig.json - // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent() +type DesiredCompilerOptionsShape = { + [K in keyof CompilerOptions]: + | { suggested: any; reason?: string } + | { + parsedValue?: any; + parsedValues?: Array; + value: any; + reason: string; + }; +}; + +function getDesiredCompilerOptions( + ts: typeof import('typescript'), + tsOptions?: CompilerOptions +): DesiredCompilerOptionsShape { + const o: DesiredCompilerOptionsShape = { target: { - parsedValue: ts.ScriptTarget.ES5, - suggested: 'es5' + suggested: 'ES2017', + reason: + 'For top-level `await`. Note: Next.js only polyfills for the esmodules target.' }, + // These are suggested values and will be set when not present in the + // tsconfig.json lib: { suggested: ['dom', 'dom.iterable', 'esnext'] }, allowJs: { suggested: true }, skipLibCheck: { suggested: true }, strict: { suggested: false }, - forceConsistentCasingInFileNames: { suggested: true }, + ...(semver.lt(ts.version, '5.0.0') + ? { forceConsistentCasingInFileNames: { suggested: true } } + : undefined), noEmit: { suggested: true }, - strictNullChecks: { suggested: true }, + ...(semver.gte(ts.version, '4.4.2') + ? { incremental: { suggested: true } } + : undefined), + // These values are required and cannot be changed by the user // Keep this in sync with the webpack config - esModuleInterop: { - value: true, - reason: 'requirement for SWC / babel' - }, - noImplicitThis: { - value: true, - reason: 'requirement for doura' - }, + // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent() module: { parsedValue: ts.ModuleKind.ESNext, // All of these values work: parsedValues: [ - ts.ModuleKind.Node16, + semver.gte(ts.version, '5.4.0') && (ts.ModuleKind as any).Preserve, ts.ModuleKind.ES2020, ts.ModuleKind.ESNext, ts.ModuleKind.CommonJS, - ts.ModuleKind.AMD + ts.ModuleKind.AMD, + ts.ModuleKind.NodeNext, + ts.ModuleKind.Node16 ], value: 'esnext', reason: 'for dynamic import() support' }, - moduleResolution: { - parsedValue: ts.ModuleResolutionKind.Node16, - // All of these values work: - parsedValues: [ - ts.ModuleResolutionKind.NodeJs, - ts.ModuleResolutionKind.Node16, - ts.ModuleResolutionKind.NodeNext - ], - value: 'node16', - reason: 'to match webpack resolution' - }, - resolveJsonModule: { value: true, reason: 'to match webpack resolution' }, - isolatedModules: { - value: true, - reason: 'requirement for SWC / Babel' - }, - jsx: { parsedValue: ts.JsxEmit.Preserve, value: 'preserve' } + // TODO: Semver check not needed once Next.js repo uses 5.4. + ...(semver.gte(ts.version, '5.4.0') && + tsOptions?.module === (ts.ModuleKind as any).Preserve + ? { + // TypeScript 5.4 introduced `Preserve`. Using `Preserve` implies + // - `moduleResolution` is `Bundler` + // - `esModuleInterop` is `true` + // - `resolveJsonModule` is `true` + // This means that if the user is using Preserve, they don't need these options + } + : { + esModuleInterop: { + value: true, + reason: 'requirement for SWC / babel' + }, + moduleResolution: { + // In TypeScript 5.0, `NodeJs` has renamed to `Node10` + parsedValue: + ts.ModuleResolutionKind.Bundler ?? + ts.ModuleResolutionKind.NodeNext ?? + (ts.ModuleResolutionKind as any).Node10 ?? + ts.ModuleResolutionKind.NodeJs, + // All of these values work: + parsedValues: [ + (ts.ModuleResolutionKind as any).Node10 ?? + ts.ModuleResolutionKind.NodeJs, + // only newer TypeScript versions have this field, it + // will be filtered for new versions of TypeScript + (ts.ModuleResolutionKind as any).Node12, + ts.ModuleResolutionKind.Node16, + ts.ModuleResolutionKind.NodeNext, + ts.ModuleResolutionKind.Bundler + ].filter(val => typeof val !== 'undefined'), + value: 'node', + reason: 'to match webpack resolution' + }, + resolveJsonModule: { + value: true, + reason: 'to match webpack resolution' + } + }), + ...(tsOptions?.verbatimModuleSyntax === true + ? undefined + : { + isolatedModules: { + value: true, + reason: 'requirement for SWC / Babel' + } + }), + jsx: { + parsedValue: ts.JsxEmit.Preserve, + value: 'preserve', + reason: 'next.js implements its own optimized jsx transform' + } }; + return o; +} + +export async function writeDefaultConfigurations( + ts: TypeScriptModule, + tsConfigPath: string, + tsConfig: TsParsedConfig, + paths: IPaths, + isFirstTimeSetup: boolean +) { const userTsConfigContent = await fs.readFile(tsConfigPath, { encoding: 'utf8' }); @@ -83,10 +140,12 @@ export async function writeDefaultConfigurations( userTsConfig.compilerOptions = {}; } + const desiredCompilerOptions = getDesiredCompilerOptions(ts, tsOptions); + const suggestedActions: string[] = []; const requiredActions: string[] = []; - for (const optionKey of Object.keys(compilerOptions)) { - const check = compilerOptions[optionKey]; + for (const optionKey of Object.keys(desiredCompilerOptions)) { + const check = desiredCompilerOptions[optionKey]; if ('suggested' in check) { if (!(optionKey in tsOptions)) { if (!userTsConfig.compilerOptions) { diff --git a/packages/service/src/project/file-presets/files/app/shuvi-app.d.ts.ts b/packages/service/src/project/file-presets/files/app/shuvi-app.d_ts.ts similarity index 100% rename from packages/service/src/project/file-presets/files/app/shuvi-app.d.ts.ts rename to packages/service/src/project/file-presets/files/app/shuvi-app.d_ts.ts diff --git a/packages/service/src/project/file-presets/index.ts b/packages/service/src/project/file-presets/index.ts index 148ddbfc1..a01e2d3a5 100644 --- a/packages/service/src/project/file-presets/index.ts +++ b/packages/service/src/project/file-presets/index.ts @@ -20,12 +20,22 @@ const getAllFiles = ( let currentFileList: FileOptionWithId[] = fileList; files.forEach((file: string) => { const filepath = path.join(dirPath, file); - const name = path.join(parent, file.replace(EXT_REGEXP, '')); + let name = path.join(parent, file.replace(EXT_REGEXP, '')); if (fs.statSync(filepath).isDirectory()) { currentFileList = getAllFiles(filepath, name, currentFileList); // Match *.ts (source) or *.js (compiled) file, but ignore *.d.ts file } else if (/\.(js|ts)$/.test(file) && !/\.d\.ts$/.test(file)) { const options = require(filepath).default; + + /** + * @note + * tsc will ignore .d.ts.ts file, + * so we need to replace it with .d_ts.ts + */ + if (name.endsWith('.d_ts')) { + name = name.replace('.d_ts', '.d.ts'); + } + currentFileList.push( originalDefineFile({ ...options, diff --git a/packages/service/tsconfig.build.json b/packages/service/tsconfig.build.json index 281deab84..2062901f7 100644 --- a/packages/service/tsconfig.build.json +++ b/packages/service/tsconfig.build.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "rootDir": "./src", "outDir": "lib", "lib": ["esnext", "DOM"], - "module": "commonjs", "esModuleInterop": true }, "include": ["src"] diff --git a/packages/shared/package.json b/packages/shared/package.json index a3e62e57e..50dd0d33d 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -26,12 +26,12 @@ }, "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "engines": { "node": ">= 16.0.0" diff --git a/packages/shared/tsconfig.build.cjs.json b/packages/shared/tsconfig.build.cjs.json new file mode 100644 index 000000000..6ac629b84 --- /dev/null +++ b/packages/shared/tsconfig.build.cjs.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/packages/shared/tsconfig.build.esm.json b/packages/shared/tsconfig.build.esm.json new file mode 100644 index 000000000..06b1f18e1 --- /dev/null +++ b/packages/shared/tsconfig.build.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": [ + "src" + ] +} diff --git a/packages/shared/tsconfig.build.json b/packages/shared/tsconfig.build.json deleted file mode 100644 index b814ecfc2..000000000 --- a/packages/shared/tsconfig.build.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ] -} diff --git a/packages/shuvi/package.json b/packages/shuvi/package.json index 3c8d12c37..9abd2c09a 100644 --- a/packages/shuvi/package.json +++ b/packages/shuvi/package.json @@ -18,9 +18,9 @@ "lib" ], "scripts": { - "dev": "tsc -p tsconfig.build.json -m commonjs -w", + "dev": "tsc -p tsconfig.build.json -w", "prebuild": "rimraf lib", - "build": "tsc -p tsconfig.build.json -m commonjs" + "build": "tsc -p tsconfig.build.json" }, "engines": { "node": ">= 16.0.0" diff --git a/packages/shuvi/src/commands/dev.ts b/packages/shuvi/src/commands/dev.ts index 5b531c515..c1ad06b9d 100644 --- a/packages/shuvi/src/commands/dev.ts +++ b/packages/shuvi/src/commands/dev.ts @@ -1,3 +1,4 @@ +import { performance } from 'perf_hooks'; import { Command } from 'commander'; import * as path from 'path'; import { createShuviServer } from '@shuvi/service'; diff --git a/packages/shuvi/src/commands/serve.ts b/packages/shuvi/src/commands/serve.ts index 14a21af25..2422040ac 100644 --- a/packages/shuvi/src/commands/serve.ts +++ b/packages/shuvi/src/commands/serve.ts @@ -1,3 +1,4 @@ +import { performance } from 'perf_hooks'; import { Command } from 'commander'; import * as path from 'path'; import { createShuviServer } from '@shuvi/service'; diff --git a/packages/shuvi/tsconfig.build.json b/packages/shuvi/tsconfig.build.json index 635ac1245..3aaddcdec 100644 --- a/packages/shuvi/tsconfig.build.json +++ b/packages/shuvi/tsconfig.build.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "outDir": "lib", - "module": "commonjs", "esModuleInterop": true }, "include": ["src"] diff --git a/packages/toolpack/package.json b/packages/toolpack/package.json index ef2ff58e9..6169985e5 100644 --- a/packages/toolpack/package.json +++ b/packages/toolpack/package.json @@ -68,7 +68,7 @@ "stream-browserify": "3.0.0", "style-loader": "2.0.0", "terser-webpack-plugin": "5.2.5", - "typescript": "4.8.4", + "typescript": "5.5.2", "vm-browserify": "1.1.2", "webpack": "5.73.0", "webpack-bundle-analyzer": "4.3.0", diff --git a/packages/toolpack/tsconfig.build.json b/packages/toolpack/tsconfig.build.json index 53d61488c..d2b257ef5 100644 --- a/packages/toolpack/tsconfig.build.json +++ b/packages/toolpack/tsconfig.build.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "outDir": "lib", - "module": "commonjs", "esModuleInterop": true }, "include": ["src/**/*.ts", "src/**/*.js"], diff --git a/packages/utils/tsconfig.build.json b/packages/utils/tsconfig.build.json index 635ac1245..3aaddcdec 100644 --- a/packages/utils/tsconfig.build.json +++ b/packages/utils/tsconfig.build.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.build.json", + "extends": "../../tsconfig.build.cjs.json", "compilerOptions": { "outDir": "lib", - "module": "commonjs", "esModuleInterop": true }, "include": ["src"] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec20fdd5a..4f72831e8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -97,7 +97,7 @@ importers: version: 2.4.1 puppeteer-core: specifier: 20.7.4 - version: 20.7.4(typescript@4.8.4) + version: 20.7.4(typescript@5.5.2) rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -109,13 +109,13 @@ importers: version: 7.3.5 ts-jest: specifier: ^29.1.5 - version: 29.1.5(jest@29.7.0)(typescript@4.8.4) + version: 29.1.5(jest@29.7.0)(typescript@5.5.2) turbo: specifier: 1.3.4 version: 1.3.4 typedoc: specifier: ^0.23.0 - version: 0.23.23(typescript@4.8.4) + version: 0.23.23(typescript@5.5.2) typedoc-plugin-markdown: specifier: ^3.12.1 version: 3.12.1(typedoc@0.23.23) @@ -123,11 +123,14 @@ importers: specifier: ^0.23.0 version: 0.23.0(typedoc@0.23.23) typescript: - specifier: 4.8.4 - version: 4.8.4 + specifier: 5.5.2 + version: 5.5.2 examples/basic: dependencies: + '@shuvi/package-esmodule': + specifier: workspace:* + version: link:../package-esmodule shuvi: specifier: workspace:* version: link:../../packages/shuvi @@ -142,8 +145,10 @@ importers: specifier: 18.0.6 version: 18.0.6 typescript: - specifier: ^4.7.4 - version: 4.8.4 + specifier: ^5.5.2 + version: 5.5.2 + + examples/package-esmodule: {} packages/compiler: dependencies: @@ -302,7 +307,7 @@ importers: version: 4.0.0(rollup@2.79.1) '@rollup/plugin-typescript': specifier: 10.0.1 - version: 10.0.1(rollup@2.79.1)(tslib@2.4.0)(typescript@4.8.4) + version: 10.0.1(rollup@2.79.1)(tslib@2.4.0)(typescript@5.5.2) '@types/babel__code-frame': specifier: 7.0.3 version: 7.0.3 @@ -682,6 +687,9 @@ importers: rimraf: specifier: 3.0.2 version: 3.0.2 + semver: + specifier: 7.3.2 + version: 7.3.2 send: specifier: 0.17.1 version: 0.17.1 @@ -716,6 +724,9 @@ importers: '@types/ejs': specifier: 3.0.4 version: 3.0.4 + '@types/semver': + specifier: 7.3.1 + version: 7.3.1 '@types/uuid': specifier: ^9.0.2 version: 9.0.2 @@ -878,7 +889,7 @@ importers: version: 2.19.0(webpack@5.73.0) fork-ts-checker-webpack-plugin: specifier: ^9.0.2 - version: 9.0.2(typescript@4.8.4)(webpack@5.73.0) + version: 9.0.2(typescript@5.5.2)(webpack@5.73.0) fs-extra: specifier: 9.0.1 version: 9.0.1 @@ -931,8 +942,8 @@ importers: specifier: 5.2.5 version: 5.2.5(esbuild@0.14.38)(webpack@5.73.0) typescript: - specifier: 4.8.4 - version: 4.8.4 + specifier: 5.5.2 + version: 5.5.2 vm-browserify: specifier: 1.1.2 version: 1.1.2 @@ -1241,7 +1252,7 @@ importers: specifier: 18.0.6 version: 18.0.6 - test/fixtures/typescript-type-error: + test/fixtures/typescript-type-error-ts4: dependencies: shuvi: specifier: workspace:* @@ -1256,6 +1267,9 @@ importers: '@types/react-dom': specifier: 18.0.6 version: 18.0.6 + typescript: + specifier: ^4.8.4 + version: 4.8.4 test/fixtures/typescript-type-error-ts5: dependencies: @@ -1273,7 +1287,7 @@ importers: specifier: 18.0.6 version: 18.0.6 typescript: - specifier: ^5.0.0 + specifier: ^5.5.2 version: 5.5.2 test/fixtures/webpack-watch-wait-file-builder: @@ -1414,7 +1428,7 @@ packages: debug: 4.3.1(supports-color@5.5.0) gensync: 1.0.0-beta.2 json5: 2.2.1 - semver: 6.3.0 + semver: 6.3.1 source-map: 0.5.7 transitivePeerDependencies: - supports-color @@ -1567,7 +1581,7 @@ packages: '@babel/core': 7.16.0 '@babel/helper-validator-option': 7.18.6 browserslist: 4.21.3 - semver: 6.3.0 + semver: 6.3.1 dev: true /@babel/helper-compilation-targets@7.24.7: @@ -4804,7 +4818,7 @@ packages: resolution: {integrity: sha512-3NsZsJIA/22P3QUyrEDNA2D133H4j224twJrdipXN38dpnIOzAbUDtOwkcJ5pXmn75w7LSQDjA4tO9dm1XlqlA==} dev: false - /@puppeteer/browsers@1.4.3(typescript@4.8.4): + /@puppeteer/browsers@1.4.3(typescript@5.5.2): resolution: {integrity: sha512-8Jfkpb8qhPQhMsNBmIY8b6+ic2kvcmHZlyvifmcNKBC5jNZf3MAKq3gryKfmrjFAYFl3naPjiKljPUq5wuolfQ==} engines: {node: '>=16.3.0'} hasBin: true @@ -4819,7 +4833,7 @@ packages: progress: 2.0.3 proxy-agent: 6.2.1 tar-fs: 3.0.3 - typescript: 4.8.4 + typescript: 5.5.2 unbzip2-stream: 1.4.3 yargs: 17.7.1 transitivePeerDependencies: @@ -4951,7 +4965,7 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-typescript@10.0.1(rollup@2.79.1)(tslib@2.4.0)(typescript@4.8.4): + /@rollup/plugin-typescript@10.0.1(rollup@2.79.1)(tslib@2.4.0)(typescript@5.5.2): resolution: {integrity: sha512-wBykxRLlX7EzL8BmUqMqk5zpx2onnmRMSw/l9M1sVfkJvdwfxogZQVNUM9gVMJbjRLDR5H6U0OMOrlDGmIV45A==} engines: {node: '>=14.0.0'} peerDependencies: @@ -4970,7 +4984,7 @@ packages: resolve: 1.22.1 rollup: 2.79.1 tslib: 2.4.0 - typescript: 4.8.4 + typescript: 5.5.2 dev: true /@rollup/pluginutils@3.1.0(rollup@2.77.2): @@ -5582,7 +5596,7 @@ packages: /@types/semver@7.3.1: resolution: {integrity: sha512-ooD/FJ8EuwlDKOI6D9HWxgIgJjMg2cuziXm/42npDC8y4NjxplBUn9loewZiBNCt44450lHAU0OSb51/UqXeag==} dependencies: - '@types/node': 12.12.7 + '@types/node': 18.19.34 dev: true /@types/send@0.14.5: @@ -5733,7 +5747,7 @@ packages: debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 - semver: 7.4.0 + semver: 7.6.2 tsutils: 3.21.0(typescript@4.8.4) typescript: 4.8.4 transitivePeerDependencies: @@ -7341,7 +7355,7 @@ packages: json-stringify-safe: 5.0.1 lodash: 4.17.21 meow: 8.1.2 - semver: 6.3.0 + semver: 6.3.1 split: 1.0.1 through2: 4.0.2 dev: true @@ -7476,7 +7490,7 @@ packages: path-type: 4.0.0 yaml: 1.10.2 - /cosmiconfig@8.3.6(typescript@4.8.4): + /cosmiconfig@8.3.6(typescript@5.5.2): resolution: {integrity: sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==} engines: {node: '>=14'} peerDependencies: @@ -7489,7 +7503,7 @@ packages: js-yaml: 4.1.0 parse-json: 5.2.0 path-type: 4.0.0 - typescript: 4.8.4 + typescript: 5.5.2 dev: false /cp-file@6.2.0: @@ -9747,7 +9761,7 @@ packages: engines: {node: '>=0.10.0'} dev: true - /fork-ts-checker-webpack-plugin@9.0.2(typescript@4.8.4)(webpack@5.73.0): + /fork-ts-checker-webpack-plugin@9.0.2(typescript@5.5.2)(webpack@5.73.0): resolution: {integrity: sha512-Uochze2R8peoN1XqlSi/rGUkDQpRogtLFocP9+PGu68zk1BDAKXfdeCdyVZpgTk8V8WFVQXdEz426VKjXLO1Gg==} engines: {node: '>=12.13.0', yarn: '>=1.0.0'} peerDependencies: @@ -9760,16 +9774,16 @@ packages: '@babel/code-frame': 7.16.7 chalk: 4.1.2 chokidar: 3.6.0 - cosmiconfig: 8.3.6(typescript@4.8.4) + cosmiconfig: 8.3.6(typescript@5.5.2) deepmerge: 4.2.2 fs-extra: 10.1.0 memfs: 3.6.0 minimatch: 3.1.2 node-abort-controller: 3.1.1 schema-utils: 3.1.1 - semver: 7.4.0 + semver: 7.6.2 tapable: 2.2.1 - typescript: 4.8.4 + typescript: 5.5.2 webpack: 5.73.0(esbuild@0.14.38) dev: false @@ -10016,7 +10030,7 @@ packages: hasBin: true dependencies: meow: 8.1.2 - semver: 6.3.0 + semver: 6.3.1 dev: true /gitconfiglocal@1.0.0: @@ -11074,7 +11088,7 @@ packages: '@babel/parser': 7.14.7 '@istanbuljs/schema': 0.1.3 istanbul-lib-coverage: 3.2.0 - semver: 6.3.0 + semver: 6.3.1 transitivePeerDependencies: - supports-color dev: true @@ -12286,6 +12300,7 @@ packages: engines: {node: '>=10'} dependencies: yallist: 4.0.0 + dev: true /lru-cache@7.18.3: resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} @@ -12326,7 +12341,7 @@ packages: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} engines: {node: '>=8'} dependencies: - semver: 6.3.0 + semver: 6.3.1 /make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} @@ -12842,7 +12857,7 @@ packages: dependencies: hosted-git-info: 4.1.0 is-core-module: 2.8.0 - semver: 7.4.0 + semver: 7.6.2 validate-npm-package-license: 3.0.4 dev: true @@ -14505,7 +14520,7 @@ packages: resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==} engines: {node: '>=6'} - /puppeteer-core@20.7.4(typescript@4.8.4): + /puppeteer-core@20.7.4(typescript@5.5.2): resolution: {integrity: sha512-7YZ1LmTo+5yM9uBNFTMJpE+lJjcIoNjKVarsYIk7o5WhgQNI9o5XgiQK5f71y1vWwr7sT/eGG75HXAehjnTBTg==} engines: {node: '>=16.3.0'} peerDependencies: @@ -14514,12 +14529,12 @@ packages: typescript: optional: true dependencies: - '@puppeteer/browsers': 1.4.3(typescript@4.8.4) + '@puppeteer/browsers': 1.4.3(typescript@5.5.2) chromium-bidi: 0.4.16(devtools-protocol@0.0.1135028) cross-fetch: 3.1.6 debug: 4.3.4 devtools-protocol: 0.0.1135028 - typescript: 4.8.4 + typescript: 5.5.2 ws: 8.13.0 transitivePeerDependencies: - bufferutil @@ -15238,11 +15253,11 @@ packages: /semver@6.3.0: resolution: {integrity: sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==} hasBin: true + dev: false /semver@6.3.1: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true - dev: true /semver@7.0.0: resolution: {integrity: sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==} @@ -15268,12 +15283,12 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 + dev: true /semver@7.6.2: resolution: {integrity: sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==} engines: {node: '>=10'} hasBin: true - dev: true /send@0.17.1: resolution: {integrity: sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==} @@ -16270,7 +16285,7 @@ packages: engines: {node: '>=8'} dev: true - /ts-jest@29.1.5(jest@29.7.0)(typescript@4.8.4): + /ts-jest@29.1.5(jest@29.7.0)(typescript@5.5.2): resolution: {integrity: sha512-UuClSYxM7byvvYfyWdFI+/2UxMmwNyJb0NPkZPQE2hew3RurV7l7zURgOHAd/1I1ZdPpe3GUsXNXAcN8TFKSIg==} engines: {node: ^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0} hasBin: true @@ -16304,7 +16319,7 @@ packages: lodash.memoize: 4.1.2 make-error: 1.3.6 semver: 7.6.2 - typescript: 4.8.4 + typescript: 5.5.2 yargs-parser: 21.1.1 dev: true @@ -16561,7 +16576,7 @@ packages: typedoc: '>=0.22.0' dependencies: handlebars: 4.7.7 - typedoc: 0.23.23(typescript@4.8.4) + typedoc: 0.23.23(typescript@5.5.2) dev: true /typedoc-plugin-missing-exports@0.23.0(typedoc@0.23.23): @@ -16569,10 +16584,10 @@ packages: peerDependencies: typedoc: 0.22.x || 0.23.x dependencies: - typedoc: 0.23.23(typescript@4.8.4) + typedoc: 0.23.23(typescript@5.5.2) dev: true - /typedoc@0.23.23(typescript@4.8.4): + /typedoc@0.23.23(typescript@5.5.2): resolution: {integrity: sha512-cg1YQWj+/BU6wq74iott513U16fbrPCbyYs04PHZgvoKJIc6EY4xNobyDZh4KMfRGW8Yjv6wwIzQyoqopKOUGw==} engines: {node: '>= 14.14'} hasBin: true @@ -16586,7 +16601,7 @@ packages: marked: 4.2.4 minimatch: 5.1.2 shiki: 0.11.1 - typescript: 4.8.4 + typescript: 5.5.2 dev: true /typescript@4.8.4: @@ -16598,7 +16613,6 @@ packages: resolution: {integrity: sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==} engines: {node: '>=14.17'} hasBin: true - dev: true /uglify-js@3.16.3: resolution: {integrity: sha512-uVbFqx9vvLhQg0iBaau9Z75AxWJ8tqM9AV890dIZCLApF4rTcyHwmAvLeEdYRs+BzYWu8Iw81F79ah0EfTXbaw==} @@ -17180,6 +17194,7 @@ packages: /yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + dev: true /yaml@1.10.2: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==} diff --git a/test/e2e/typescript-ingnoreBuildError.test.ts b/test/e2e/typescript-ingnoreBuildError.test.ts index 3f341e0fe..846e8cce8 100644 --- a/test/e2e/typescript-ingnoreBuildError.test.ts +++ b/test/e2e/typescript-ingnoreBuildError.test.ts @@ -4,7 +4,7 @@ import { SpawnSyncReturns } from 'child_process'; jest.setTimeout(5 * 60 * 1000); describe('Test build process with ignoreBuildErrors setting', () => { - const fixture = 'typescript-type-error'; + const fixture = 'typescript-type-error-ts4'; test(`build fail without ignoreBuildErrors`, async () => { let error = false; diff --git a/test/fixtures/dll/tsconfig.json b/test/fixtures/dll/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/dll/tsconfig.json +++ b/test/fixtures/dll/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/file-type/tsconfig.json b/test/fixtures/file-type/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/file-type/tsconfig.json +++ b/test/fixtures/file-type/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/loader/tsconfig.json b/test/fixtures/loader/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/loader/tsconfig.json +++ b/test/fixtures/loader/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/model/tsconfig.json b/test/fixtures/model/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/model/tsconfig.json +++ b/test/fixtures/model/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/prefetch-link/tsconfig.json b/test/fixtures/prefetch-link/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/prefetch-link/tsconfig.json +++ b/test/fixtures/prefetch-link/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/tsconfig-path-refresh/tsconfig.json b/test/fixtures/tsconfig-path-refresh/tsconfig.json index da957314c..5d5dc2e33 100644 --- a/test/fixtures/tsconfig-path-refresh/tsconfig.json +++ b/test/fixtures/tsconfig-path-refresh/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": false, @@ -17,13 +21,29 @@ "jsx": "preserve", "baseUrl": "./", "paths": { - "@shuvi/runtime": [".shuvi/app/runtime"], - "@shuvi/runtime/*": [".shuvi/app/runtime/*"], - "@lib/*": ["src/lib/first-lib/*"], - "@comp/*": ["src/components/*"], - "@myComponent2": ["src/components/component-2.tsx"] - } + "@shuvi/runtime": [ + ".shuvi/app/runtime" + ], + "@shuvi/runtime/*": [ + ".shuvi/app/runtime/*" + ], + "@lib/*": [ + "src/lib/first-lib/*" + ], + "@comp/*": [ + "src/components/*" + ], + "@myComponent2": [ + "src/components/component-2.tsx" + ] + }, + "incremental": true }, - "include": [".shuvi/app/shuvi-app.d.ts", "src"], - "exclude": ["node_modules"] + "include": [ + ".shuvi/app/shuvi-app.d.ts", + "src" + ], + "exclude": [ + "node_modules" + ] } diff --git a/test/fixtures/typescript-type-error/package.json b/test/fixtures/typescript-type-error-ts4/package.json similarity index 57% rename from test/fixtures/typescript-type-error/package.json rename to test/fixtures/typescript-type-error-ts4/package.json index 5adb601fa..cd7286db6 100644 --- a/test/fixtures/typescript-type-error/package.json +++ b/test/fixtures/typescript-type-error-ts4/package.json @@ -1,11 +1,12 @@ { - "name": "fixture-typescript-error", + "name": "fixture-typescript-error-ts4", "dependencies": { "shuvi": "workspace:*" }, "devDependencies": { "@types/node": "18.0.6", "@types/react": "18.0.9", - "@types/react-dom": "18.0.6" + "@types/react-dom": "18.0.6", + "typescript": "^4.8.4" } } diff --git a/test/fixtures/typescript-type-error/shuvi.config.ts b/test/fixtures/typescript-type-error-ts4/shuvi.config.ts similarity index 100% rename from test/fixtures/typescript-type-error/shuvi.config.ts rename to test/fixtures/typescript-type-error-ts4/shuvi.config.ts diff --git a/test/fixtures/typescript-type-error/src/routes/page.tsx b/test/fixtures/typescript-type-error-ts4/src/routes/page.tsx similarity index 100% rename from test/fixtures/typescript-type-error/src/routes/page.tsx rename to test/fixtures/typescript-type-error-ts4/src/routes/page.tsx diff --git a/test/fixtures/typescript-type-error/tsconfig.json b/test/fixtures/typescript-type-error-ts4/tsconfig.json similarity index 96% rename from test/fixtures/typescript-type-error/tsconfig.json rename to test/fixtures/typescript-type-error-ts4/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/typescript-type-error/tsconfig.json +++ b/test/fixtures/typescript-type-error-ts4/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/typescript-type-error-ts5/package.json b/test/fixtures/typescript-type-error-ts5/package.json index ae00dec20..2c3c099d0 100644 --- a/test/fixtures/typescript-type-error-ts5/package.json +++ b/test/fixtures/typescript-type-error-ts5/package.json @@ -1,5 +1,5 @@ { - "name": "fixture-typescript-error", + "name": "fixture-typescript-error-ts5", "dependencies": { "shuvi": "workspace:*" }, @@ -7,6 +7,6 @@ "@types/node": "18.0.6", "@types/react": "18.0.9", "@types/react-dom": "18.0.6", - "typescript": "^5.0.0" + "typescript": "^5.5.2" } } diff --git a/test/fixtures/typescript-type-error-ts5/tsconfig.json b/test/fixtures/typescript-type-error-ts5/tsconfig.json index 7117de208..1a90bcea5 100644 --- a/test/fixtures/typescript-type-error-ts5/tsconfig.json +++ b/test/fixtures/typescript-type-error-ts5/tsconfig.json @@ -15,7 +15,7 @@ "esModuleInterop": true, "noImplicitThis": true, "module": "esnext", - "moduleResolution": "node16", + "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/fixtures/typescript/tsconfig.json b/test/fixtures/typescript/tsconfig.json index 7117de208..7f4703372 100644 --- a/test/fixtures/typescript/tsconfig.json +++ b/test/fixtures/typescript/tsconfig.json @@ -27,7 +27,8 @@ "@shuvi/runtime/*": [ ".shuvi/app/runtime/*" ] - } + }, + "incremental": true }, "include": [ ".shuvi/app/shuvi-app.d.ts", diff --git a/test/packages/plugin-sample/package.json b/test/packages/plugin-sample/package.json index ccd2ed26f..cf8292f6d 100644 --- a/test/packages/plugin-sample/package.json +++ b/test/packages/plugin-sample/package.json @@ -23,12 +23,12 @@ "types": "lib/index.d.ts", "scripts": { "dev": "run-p watch:*", - "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w", - "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "watch:esm": "tsc -p tsconfig.build.esm.json -w", + "watch:cjs": "tsc -p tsconfig.build.cjs.json -w", "prebuild": "rimraf lib esm", "build": "run-p build:*", - "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm", - "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build:esm": "tsc -p tsconfig.build.esm.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json" }, "dependencies": { "@shuvi/hook": "workspace:*", diff --git a/test/packages/plugin-sample/tsconfig.build.cjs.json b/test/packages/plugin-sample/tsconfig.build.cjs.json new file mode 100644 index 000000000..8ac0eefe0 --- /dev/null +++ b/test/packages/plugin-sample/tsconfig.build.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.build.cjs.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "lib" + }, + "include": ["src"], + "exclude": ["**/__tests__/**"] +} diff --git a/test/packages/plugin-sample/tsconfig.build.esm.json b/test/packages/plugin-sample/tsconfig.build.esm.json new file mode 100644 index 000000000..5c2e703eb --- /dev/null +++ b/test/packages/plugin-sample/tsconfig.build.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.build.esm.json", + "compilerOptions": { + "rootDir": "./src", + "lib": ["esnext", "DOM"], + "outDir": "esm" + }, + "include": ["src"], + "exclude": ["**/__tests__/**"] +} diff --git a/test/packages/plugin-sample/tsconfig.build.json b/test/packages/plugin-sample/tsconfig.build.json deleted file mode 100644 index f47145394..000000000 --- a/test/packages/plugin-sample/tsconfig.build.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig.build.json", - "compilerOptions": { - "rootDir": "./src", - "lib": ["esnext", "DOM"] - }, - "include": [ - "src" - ], - "exclude": ["**/__tests__/**"] -} diff --git a/test/packages/preset-sample/package.json b/test/packages/preset-sample/package.json index 5389dc8f6..2f93b8e41 100644 --- a/test/packages/preset-sample/package.json +++ b/test/packages/preset-sample/package.json @@ -19,9 +19,9 @@ }, "types": "lib/index.d.ts", "scripts": { - "dev": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w", + "dev": "tsc -p tsconfig.build.json -w", "prebuild": "rimraf lib", - "build": "tsc -p tsconfig.build.json -m commonjs --outDir lib" + "build": "tsc -p tsconfig.build.json" }, "dependencies": { "@shuvi/service": "workspace:*", diff --git a/test/packages/preset-sample/tsconfig.build.json b/test/packages/preset-sample/tsconfig.build.json index f47145394..33c5b2153 100644 --- a/test/packages/preset-sample/tsconfig.build.json +++ b/test/packages/preset-sample/tsconfig.build.json @@ -1,8 +1,9 @@ { - "extends": "../../../tsconfig.build.json", + "extends": "../../../tsconfig.build.cjs.json", "compilerOptions": { "rootDir": "./src", - "lib": ["esnext", "DOM"] + "lib": ["esnext", "DOM"], + "outDir": "lib" }, "include": [ "src" diff --git a/tsconfig.build.json b/tsconfig.base.json similarity index 91% rename from tsconfig.build.json rename to tsconfig.base.json index 253841902..2d1d2e3aa 100644 --- a/tsconfig.build.json +++ b/tsconfig.base.json @@ -4,8 +4,6 @@ "allowJs": true, "target": "es6", "lib": ["esnext"], - "module": "esnext", - "moduleResolution": "node16", "skipLibCheck": true, "strict": true, "strictNullChecks": true, diff --git a/tsconfig.build.cjs.json b/tsconfig.build.cjs.json new file mode 100644 index 000000000..f5b5266d2 --- /dev/null +++ b/tsconfig.build.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "node16", + "moduleResolution": "node16", + }, + "include": [ + "src" + ] +} diff --git a/tsconfig.build.esm.json b/tsconfig.build.esm.json new file mode 100644 index 000000000..c905c2a8e --- /dev/null +++ b/tsconfig.build.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + }, + "include": [ + "src" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 72ca0b8cf..d8e7512bd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,10 @@ { - "extends": "./tsconfig.build.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "baseUrl": ".", + "module": "node16", + "moduleResolution": "node16", + "noEmit": true, "paths": { "@shuvi/router-react": ["packages/router-react/src/index"], "@shuvi/router": ["packages/router/src/index"],