From f397bfb21f0b071009b0482a01abcf434c9cd913 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 4 Jun 2024 20:44:53 +0800 Subject: [PATCH] feat(shared): initialize shared package --- e2e/cases/define/index.test.ts | 1 - e2e/package.json | 2 +- packages/core/bin/rslib.js | 9 +++- packages/core/modern.config.ts | 19 ++++++++ packages/core/package.json | 13 ++++-- packages/shared/modern.config.ts | 6 +++ packages/shared/package.json | 47 +++++++++++++++++++ packages/shared/src/index.ts | 1 + packages/shared/src/logger.ts | 6 +++ packages/shared/tsconfig.json | 9 ++++ pnpm-lock.yaml | 79 ++++++++++++++++++++++++-------- scripts/tsconfig/base.json | 3 +- 12 files changed, 165 insertions(+), 30 deletions(-) create mode 100644 packages/shared/modern.config.ts create mode 100644 packages/shared/package.json create mode 100644 packages/shared/src/index.ts create mode 100644 packages/shared/src/logger.ts create mode 100644 packages/shared/tsconfig.json diff --git a/e2e/cases/define/index.test.ts b/e2e/cases/define/index.test.ts index 3a9e7920e..8bd511e41 100644 --- a/e2e/cases/define/index.test.ts +++ b/e2e/cases/define/index.test.ts @@ -3,7 +3,6 @@ import { expect, test } from 'vitest'; import { globContentJSON } from '#helper'; test.fails('define', async () => { - // @ts-expect-error follow conventional delete process.env.NODE_ENV; const rslibConfig = { diff --git a/e2e/package.json b/e2e/package.json index bd278e235..11b95c1ea 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -13,7 +13,7 @@ "@rslib/core": "workspace:*", "@rslib/tsconfig": "workspace:*", "@types/fs-extra": "^11.0.4", - "@types/node": "16.x", + "@types/node": "18.x", "fast-glob": "^3.3.2", "fs-extra": "^11.2.0", "typescript": "^5.4.5" diff --git a/packages/core/bin/rslib.js b/packages/core/bin/rslib.js index e0345a2bd..5cd9b2520 100755 --- a/packages/core/bin/rslib.js +++ b/packages/core/bin/rslib.js @@ -1,8 +1,13 @@ #!/usr/bin/env node +import { logger } from '@rslib/shared'; +import { runCli } from '../dist/es/cli.js'; async function main() { - const { runCli } = require('../dist/cli'); - runCli(); + try { + runCli(); + } catch (err) { + logger.error(err); + } } main(); diff --git a/packages/core/modern.config.ts b/packages/core/modern.config.ts index 3abd1cf84..ca9148bbc 100644 --- a/packages/core/modern.config.ts +++ b/packages/core/modern.config.ts @@ -9,6 +9,25 @@ export default defineConfig({ format: 'cjs', autoExtension: true, target: 'es2020', + outDir: './dist/lib', + dts: false, + }, + { + input: ['src'], + buildType: 'bundleless', + format: 'esm', + autoExtension: true, + target: 'es2020', + dts: false, + outDir: './dist/es', + }, + { + input: ['src'], + buildType: 'bundleless', + outDir: './dist/types', + dts: { + only: true, + }, }, ], }); diff --git a/packages/core/package.json b/packages/core/package.json index ffb64f6ae..1ccf24922 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -12,16 +12,18 @@ "directory": "packages/core" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { - "types": "./dist/main.d.ts", - "default": "./dist/main.js" + "types": "./dist/types/main.d.ts", + "import": "./dist/es/main.js", + "require": "./dist/lib/main.cjs" }, "./package.json": "./package.json" }, - "main": "./dist/main.js", - "types": "./dist/main.d.ts", + "main": "./dist/lib/main.cjs", + "module": "./dist/es/main.js", + "types": "./dist/lib/main.d.ts", "bin": { "rslib": "./bin/rslib.js" }, @@ -39,6 +41,7 @@ "commander": "^12.0.0" }, "devDependencies": { + "@rslib/shared": "workspace:*", "@rslib/tsconfig": "workspace:*", "typescript": "^5.4.5" }, diff --git a/packages/shared/modern.config.ts b/packages/shared/modern.config.ts new file mode 100644 index 000000000..68fb4339d --- /dev/null +++ b/packages/shared/modern.config.ts @@ -0,0 +1,6 @@ +import { defineConfig, moduleTools } from '@modern-js/module-tools'; + +export default defineConfig({ + plugins: [moduleTools()], + buildPreset: 'npm-library', +}); diff --git a/packages/shared/package.json b/packages/shared/package.json new file mode 100644 index 000000000..096a5d80e --- /dev/null +++ b/packages/shared/package.json @@ -0,0 +1,47 @@ +{ + "name": "@rslib/shared", + "version": "0.0.0", + "description": "The internal shared modules and dependencies of Rslib.", + "homepage": "https://rslib.dev", + "bugs": { + "url": "https://github.com/web-infra-dev/rslib/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/web-infra-dev/rslib", + "directory": "packages/shared" + }, + "license": "MIT", + "type": "module", + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/es/index.js", + "require": "./dist/lib/index.js" + } + }, + "main": "./dist/lib/index.js", + "module": "./dist/es/index.js", + "types": "./dist/types/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "modern build", + "dev": "modern build --watch" + }, + "devDependencies": { + "@rslib/tsconfig": "workspace:*", + "@types/node": "18.x", + "rslog": "^1.2.2", + "typescript": "^5.4.5" + }, + "engines": { + "node": ">=16.0.0" + }, + "publishConfig": { + "access": "public", + "provenance": true, + "registry": "https://registry.npmjs.org/" + } +} diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts new file mode 100644 index 000000000..1ff09efd4 --- /dev/null +++ b/packages/shared/src/index.ts @@ -0,0 +1 @@ +export * from './logger'; diff --git a/packages/shared/src/logger.ts b/packages/shared/src/logger.ts new file mode 100644 index 000000000..3ac7be551 --- /dev/null +++ b/packages/shared/src/logger.ts @@ -0,0 +1,6 @@ +import { type Logger, logger } from 'rslog'; + +// TODO: add rslib related logging functions + +export { logger }; +export type { Logger }; diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json new file mode 100644 index 000000000..ce0ce1b65 --- /dev/null +++ b/packages/shared/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@rslib/tsconfig/base", + "compilerOptions": { + "module": "ESNext", + "moduleResolution": "Bundler" + }, + "include": ["src"], + "exclude": ["**/node_modules"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da4a11649..f3148f5ba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,7 +13,7 @@ importers: version: 1.7.0 '@modern-js/module-tools': specifier: ^2.48.6 - version: 2.48.6 + version: 2.48.6(typescript@5.4.5) check-dependency-version-consistency: specifier: ^4.1.0 version: 4.1.0 @@ -31,7 +31,7 @@ importers: version: 2.10.0 vitest: specifier: ^1.5.0 - version: 1.5.0 + version: 1.5.0(@types/node@18.19.34)(terser@5.19.2) e2e: devDependencies: @@ -48,8 +48,8 @@ importers: specifier: ^11.0.4 version: 11.0.4 '@types/node': - specifier: 16.x - version: 16.18.96 + specifier: 18.x + version: 18.19.34 fast-glob: specifier: ^3.3.2 version: 3.3.2 @@ -72,6 +72,9 @@ importers: specifier: ^12.0.0 version: 12.0.0 devDependencies: + '@rslib/shared': + specifier: workspace:* + version: link:../shared '@rslib/tsconfig': specifier: workspace:* version: link:../../scripts/tsconfig @@ -79,6 +82,21 @@ importers: specifier: ^5.4.5 version: 5.4.5 + packages/shared: + devDependencies: + '@rslib/tsconfig': + specifier: workspace:* + version: link:../../scripts/tsconfig + '@types/node': + specifier: 18.x + version: 18.19.34 + rslog: + specifier: ^1.2.2 + version: 1.2.2 + typescript: + specifier: ^5.4.5 + version: 5.4.5 + scripts/tsconfig: dependencies: '@tsconfig/strictest': @@ -1085,8 +1103,8 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} - '@types/node@16.18.96': - resolution: {integrity: sha512-84iSqGXoO+Ha16j8pRZ/L90vDMKX04QTYMTfYeE1WrjWaZXuchBehGUZEpNgx7JnmlrIHdnABmpjrQjhCnNldQ==} + '@types/node@18.19.34': + resolution: {integrity: sha512-eXF4pfBNV5DAMKGbI02NnDtWrQ40hAN558/2vvS4gMpMIxaf6JmD7YjnZbq0Q9TDSSkKBamime8ewRoomHdt4g==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -2306,6 +2324,10 @@ packages: resolution: {integrity: sha512-XDMoa858LLZnf4i2kUwyjBQGplXaoSoIfMQf9iji2ano5t1OfSiJsSYpHeOH26DJEc5hdje/4K3wiT6TWL3cRA==} engines: {node: '>=14.17.6'} + rslog@1.2.2: + resolution: {integrity: sha512-tZP8KjrI1nz6qOYCrFxAV7cfmfS2GV94jotU2zOmF/6ByO1zNvGR6/+0inylpjqyBjAdnnutTUW0m4th06bSTw==} + engines: {node: '>=14.17.6'} + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -2621,6 +2643,9 @@ packages: unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + universalify@0.1.2: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} engines: {node: '>= 4.0.0'} @@ -3441,7 +3466,7 @@ snapshots: '@modern-js/utils': 2.48.6 '@swc/helpers': 0.5.3 - '@modern-js/module-tools@2.48.6': + '@modern-js/module-tools@2.48.6(typescript@5.4.5)': dependencies: '@ampproject/remapping': 2.3.0 '@ast-grep/napi': 0.16.0 @@ -3470,6 +3495,8 @@ snapshots: tapable: 2.2.1 terser: 5.19.2 tsconfig-paths-webpack-plugin: 4.1.0 + optionalDependencies: + typescript: 5.4.5 transitivePeerDependencies: - debug - eslint @@ -3651,7 +3678,7 @@ snapshots: '@rspack/core': 0.6.1(@swc/helpers@0.5.3) '@swc/helpers': 0.5.3 core-js: 3.36.1 - html-webpack-plugin: html-rspack-plugin@5.6.2(@rspack/core@0.6.1) + html-webpack-plugin: html-rspack-plugin@5.6.2(@rspack/core@0.6.1(@swc/helpers@0.5.3)) postcss: 8.4.38 '@rsbuild/shared@0.6.2(@swc/helpers@0.5.3)': @@ -3705,7 +3732,6 @@ snapshots: dependencies: '@module-federation/runtime-tools': 0.0.8 '@rspack/binding': 0.6.1 - '@swc/helpers': 0.5.3 browserslist: 4.23.0 enhanced-resolve: 5.12.0 events: 3.3.0 @@ -3717,6 +3743,8 @@ snapshots: webpack-sources: 3.2.3 zod: 3.22.4 zod-validation-error: 1.3.1(zod@3.22.4) + optionalDependencies: + '@swc/helpers': 0.5.3 '@sinclair/typebox@0.27.8': {} @@ -3731,19 +3759,21 @@ snapshots: '@types/fs-extra@11.0.4': dependencies: '@types/jsonfile': 6.1.4 - '@types/node': 16.18.96 + '@types/node': 18.19.34 '@types/js-yaml@4.0.9': {} '@types/jsonfile@6.1.4': dependencies: - '@types/node': 16.18.96 + '@types/node': 18.19.34 '@types/minimist@1.2.5': {} '@types/node@12.20.55': {} - '@types/node@16.18.96': {} + '@types/node@18.19.34': + dependencies: + undici-types: 5.26.5 '@types/normalize-package-data@2.4.4': {} @@ -4480,11 +4510,12 @@ snapshots: hosted-git-info@2.8.9: {} - html-rspack-plugin@5.6.2(@rspack/core@0.6.1): + html-rspack-plugin@5.6.2(@rspack/core@0.6.1(@swc/helpers@0.5.3)): dependencies: - '@rspack/core': 0.6.1(@swc/helpers@0.5.3) lodash: 4.17.21 tapable: 2.2.1 + optionalDependencies: + '@rspack/core': 0.6.1(@swc/helpers@0.5.3) human-id@1.0.2: {} @@ -5054,6 +5085,8 @@ snapshots: rslog@1.2.1: {} + rslog@1.2.2: {} + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -5382,6 +5415,8 @@ snapshots: has-symbols: 1.0.3 which-boxed-primitive: 1.0.2 + undici-types@5.26.5: {} + universalify@0.1.2: {} universalify@2.0.1: {} @@ -5403,13 +5438,13 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 - vite-node@1.5.0: + vite-node@1.5.0(@types/node@18.19.34)(terser@5.19.2): dependencies: cac: 6.7.14 debug: 4.3.4 pathe: 1.1.2 picocolors: 1.0.0 - vite: 5.2.9 + vite: 5.2.9(@types/node@18.19.34)(terser@5.19.2) transitivePeerDependencies: - '@types/node' - less @@ -5420,15 +5455,17 @@ snapshots: - supports-color - terser - vite@5.2.9: + vite@5.2.9(@types/node@18.19.34)(terser@5.19.2): dependencies: esbuild: 0.20.2 postcss: 8.4.38 rollup: 4.14.3 optionalDependencies: + '@types/node': 18.19.34 fsevents: 2.3.3 + terser: 5.19.2 - vitest@1.5.0: + vitest@1.5.0(@types/node@18.19.34)(terser@5.19.2): dependencies: '@vitest/expect': 1.5.0 '@vitest/runner': 1.5.0 @@ -5447,9 +5484,11 @@ snapshots: strip-literal: 2.1.0 tinybench: 2.7.0 tinypool: 0.8.4 - vite: 5.2.9 - vite-node: 1.5.0 + vite: 5.2.9(@types/node@18.19.34)(terser@5.19.2) + vite-node: 1.5.0(@types/node@18.19.34)(terser@5.19.2) why-is-node-running: 2.2.2 + optionalDependencies: + '@types/node': 18.19.34 transitivePeerDependencies: - less - lightningcss diff --git a/scripts/tsconfig/base.json b/scripts/tsconfig/base.json index a0af91f84..f95780475 100644 --- a/scripts/tsconfig/base.json +++ b/scripts/tsconfig/base.json @@ -15,7 +15,8 @@ "jsx": "preserve", "resolveJsonModule": true, "moduleResolution": "Bundler", - "useDefineForClassFields": true + "useDefineForClassFields": true, + "noPropertyAccessFromIndexSignature": false }, "$schema": "https://json.schemastore.org/tsconfig", "display": "Base"