@simplysm/sd-cli 13.0.99 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/build.js +29 -19
- package/dist/commands/build.js.map +1 -6
- package/dist/commands/check.d.ts +1 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +130 -115
- package/dist/commands/check.js.map +1 -6
- package/dist/commands/dev.d.ts +6 -7
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +24 -14
- package/dist/commands/dev.js.map +1 -6
- package/dist/commands/lint.d.ts +1 -1
- package/dist/commands/lint.js +158 -116
- package/dist/commands/lint.js.map +1 -6
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +637 -510
- package/dist/commands/publish.js.map +1 -6
- package/dist/commands/replace-deps.js +12 -12
- package/dist/commands/replace-deps.js.map +1 -6
- package/dist/commands/typecheck.d.ts +5 -30
- package/dist/commands/typecheck.d.ts.map +1 -1
- package/dist/commands/typecheck.js +144 -207
- package/dist/commands/typecheck.js.map +1 -6
- package/dist/commands/watch.d.ts +6 -4
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +25 -16
- package/dist/commands/watch.js.map +1 -6
- package/dist/engines/NgtscEngine.d.ts +47 -0
- package/dist/engines/NgtscEngine.d.ts.map +1 -0
- package/dist/engines/NgtscEngine.js +151 -0
- package/dist/engines/NgtscEngine.js.map +1 -0
- package/dist/engines/ServerEsbuildEngine.d.ts +47 -0
- package/dist/engines/ServerEsbuildEngine.d.ts.map +1 -0
- package/dist/engines/ServerEsbuildEngine.js +159 -0
- package/dist/engines/ServerEsbuildEngine.js.map +1 -0
- package/dist/engines/TscEngine.d.ts +47 -0
- package/dist/engines/TscEngine.d.ts.map +1 -0
- package/dist/engines/TscEngine.js +153 -0
- package/dist/engines/TscEngine.js.map +1 -0
- package/dist/engines/ViteEngine.d.ts +49 -0
- package/dist/engines/ViteEngine.d.ts.map +1 -0
- package/dist/engines/ViteEngine.js +161 -0
- package/dist/engines/ViteEngine.js.map +1 -0
- package/dist/engines/index.d.ts +26 -0
- package/dist/engines/index.d.ts.map +1 -0
- package/dist/engines/index.js +30 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/engines/types.d.ts +77 -0
- package/dist/engines/types.d.ts.map +1 -0
- package/dist/engines/types.js +2 -0
- package/dist/engines/types.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -6
- package/dist/infra/ResultCollector.d.ts +1 -1
- package/dist/infra/ResultCollector.d.ts.map +1 -1
- package/dist/infra/ResultCollector.js +30 -27
- package/dist/infra/ResultCollector.js.map +1 -6
- package/dist/infra/SignalHandler.js +45 -42
- package/dist/infra/SignalHandler.js.map +1 -6
- package/dist/infra/WorkerManager.js +56 -53
- package/dist/infra/WorkerManager.js.map +1 -6
- package/dist/orchestrators/BuildOrchestrator.d.ts +33 -1
- package/dist/orchestrators/BuildOrchestrator.d.ts.map +1 -1
- package/dist/orchestrators/BuildOrchestrator.js +314 -309
- package/dist/orchestrators/BuildOrchestrator.js.map +1 -6
- package/dist/orchestrators/DevWatchOrchestrator.d.ts +60 -0
- package/dist/orchestrators/DevWatchOrchestrator.d.ts.map +1 -0
- package/dist/orchestrators/DevWatchOrchestrator.js +465 -0
- package/dist/orchestrators/DevWatchOrchestrator.js.map +1 -0
- package/dist/sd-cli-entry.d.ts.map +1 -1
- package/dist/sd-cli-entry.js +190 -266
- package/dist/sd-cli-entry.js.map +1 -6
- package/dist/sd-cli.js +77 -49
- package/dist/sd-cli.js.map +1 -6
- package/dist/sd-config.types.d.ts +2 -0
- package/dist/sd-config.types.d.ts.map +1 -1
- package/dist/sd-config.types.js +2 -1
- package/dist/sd-config.types.js.map +1 -6
- package/dist/utils/angular-build.d.ts +77 -0
- package/dist/utils/angular-build.d.ts.map +1 -0
- package/dist/utils/angular-build.js +84 -0
- package/dist/utils/angular-build.js.map +1 -0
- package/dist/utils/build-env.js +9 -9
- package/dist/utils/build-env.js.map +1 -6
- package/dist/utils/concurrency.d.ts +15 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +38 -0
- package/dist/utils/concurrency.js.map +1 -0
- package/dist/utils/copy-public.js +104 -87
- package/dist/utils/copy-public.js.map +1 -6
- package/dist/utils/copy-src.js +49 -35
- package/dist/utils/copy-src.js.map +1 -6
- package/dist/utils/esbuild-config.d.ts +0 -29
- package/dist/utils/esbuild-config.d.ts.map +1 -1
- package/dist/utils/esbuild-config.js +151 -218
- package/dist/utils/esbuild-config.js.map +1 -6
- package/dist/utils/ngtsc-build-core.d.ts +49 -0
- package/dist/utils/ngtsc-build-core.d.ts.map +1 -0
- package/dist/utils/ngtsc-build-core.js +250 -0
- package/dist/utils/ngtsc-build-core.js.map +1 -0
- package/dist/utils/output-path-rewriter.d.ts +23 -0
- package/dist/utils/output-path-rewriter.d.ts.map +1 -0
- package/dist/utils/output-path-rewriter.js +74 -0
- package/dist/utils/output-path-rewriter.js.map +1 -0
- package/dist/utils/output-utils.js +55 -40
- package/dist/utils/output-utils.js.map +1 -6
- package/dist/utils/package-utils.d.ts +8 -0
- package/dist/utils/package-utils.d.ts.map +1 -1
- package/dist/utils/package-utils.js +103 -73
- package/dist/utils/package-utils.js.map +1 -6
- package/dist/utils/rebuild-manager.js +41 -44
- package/dist/utils/rebuild-manager.js.map +1 -6
- package/dist/utils/replace-deps.js +283 -184
- package/dist/utils/replace-deps.js.map +1 -6
- package/dist/utils/scss-compiler.d.ts +10 -0
- package/dist/utils/scss-compiler.d.ts.map +1 -0
- package/dist/utils/scss-compiler.js +36 -0
- package/dist/utils/scss-compiler.js.map +1 -0
- package/dist/utils/sd-config.js +29 -19
- package/dist/utils/sd-config.js.map +1 -6
- package/dist/utils/tsc-build.d.ts +36 -0
- package/dist/utils/tsc-build.d.ts.map +1 -0
- package/dist/utils/tsc-build.js +130 -0
- package/dist/utils/tsc-build.js.map +1 -0
- package/dist/utils/tsconfig.d.ts +7 -26
- package/dist/utils/tsconfig.d.ts.map +1 -1
- package/dist/utils/tsconfig.js +39 -64
- package/dist/utils/tsconfig.js.map +1 -6
- package/dist/utils/typecheck-non-package.d.ts +18 -0
- package/dist/utils/typecheck-non-package.d.ts.map +1 -0
- package/dist/utils/typecheck-non-package.js +64 -0
- package/dist/utils/typecheck-non-package.js.map +1 -0
- package/dist/utils/typecheck-serialization.js +58 -40
- package/dist/utils/typecheck-serialization.js.map +1 -6
- package/dist/utils/worker-events.js +48 -40
- package/dist/utils/worker-events.js.map +1 -6
- package/dist/utils/worker-utils.js +48 -28
- package/dist/utils/worker-utils.js.map +1 -6
- package/dist/vitest-plugin.d.ts +9 -0
- package/dist/vitest-plugin.d.ts.map +1 -0
- package/dist/vitest-plugin.js +85 -0
- package/dist/vitest-plugin.js.map +1 -0
- package/dist/workers/library-build.worker.d.ts +54 -0
- package/dist/workers/library-build.worker.d.ts.map +1 -0
- package/dist/workers/library-build.worker.js +97 -0
- package/dist/workers/library-build.worker.js.map +1 -0
- package/dist/workers/lint.worker.js +9 -6
- package/dist/workers/lint.worker.js.map +1 -6
- package/dist/workers/ngtsc-build.worker.d.ts +23 -0
- package/dist/workers/ngtsc-build.worker.d.ts.map +1 -0
- package/dist/workers/ngtsc-build.worker.js +98 -0
- package/dist/workers/ngtsc-build.worker.js.map +1 -0
- package/dist/workers/{server.worker.d.ts → server-build.worker.d.ts} +39 -29
- package/dist/workers/server-build.worker.d.ts.map +1 -0
- package/dist/workers/server-build.worker.js +399 -0
- package/dist/workers/server-build.worker.js.map +1 -0
- package/dist/workers/server-runtime.worker.d.ts +3 -2
- package/dist/workers/server-runtime.worker.d.ts.map +1 -1
- package/dist/workers/server-runtime.worker.js +100 -95
- package/dist/workers/server-runtime.worker.js.map +1 -6
- package/dist/workers/vite-build.worker.d.ts +56 -0
- package/dist/workers/vite-build.worker.d.ts.map +1 -0
- package/dist/workers/vite-build.worker.js +167 -0
- package/dist/workers/vite-build.worker.js.map +1 -0
- package/package.json +10 -16
- package/src/commands/check.ts +21 -3
- package/src/commands/dev.ts +10 -8
- package/src/commands/lint.ts +1 -1
- package/src/commands/publish.ts +4 -0
- package/src/commands/typecheck.ts +89 -256
- package/src/commands/watch.ts +9 -8
- package/src/engines/NgtscEngine.ts +190 -0
- package/src/engines/ServerEsbuildEngine.ts +195 -0
- package/src/engines/TscEngine.ts +189 -0
- package/src/engines/ViteEngine.ts +203 -0
- package/src/engines/index.ts +49 -0
- package/src/engines/types.ts +79 -0
- package/src/index.ts +0 -3
- package/src/infra/ResultCollector.ts +1 -1
- package/src/orchestrators/BuildOrchestrator.ts +87 -157
- package/src/orchestrators/DevWatchOrchestrator.ts +573 -0
- package/src/sd-cli-entry.ts +13 -116
- package/src/sd-config.types.ts +2 -0
- package/src/utils/angular-build.ts +157 -0
- package/src/utils/concurrency.ts +43 -0
- package/src/utils/esbuild-config.ts +1 -122
- package/src/utils/ngtsc-build-core.ts +379 -0
- package/src/utils/output-path-rewriter.ts +82 -0
- package/src/utils/package-utils.ts +20 -0
- package/src/utils/scss-compiler.ts +58 -0
- package/src/utils/tsc-build.ts +175 -0
- package/src/utils/tsconfig.ts +27 -95
- package/src/utils/typecheck-non-package.ts +87 -0
- package/src/vitest-plugin.ts +118 -0
- package/src/workers/library-build.worker.ts +153 -0
- package/src/workers/ngtsc-build.worker.ts +146 -0
- package/src/workers/server-build.worker.ts +565 -0
- package/src/workers/server-runtime.worker.ts +17 -26
- package/src/workers/vite-build.worker.ts +252 -0
- package/tests/commands/check.spec.ts +276 -0
- package/tests/commands/dev.spec.ts +53 -0
- package/tests/commands/lint.spec.ts +243 -0
- package/tests/commands/publish.spec.ts +1159 -0
- package/tests/commands/typecheck.spec.ts +294 -0
- package/tests/commands/watch.spec.ts +53 -0
- package/tests/engines/engine-selection.spec.ts +247 -0
- package/tests/engines/ngtsc-engine.spec.ts +274 -0
- package/tests/engines/server-esbuild-engine.spec.ts +256 -0
- package/tests/engines/tsc-engine.spec.ts +213 -0
- package/tests/engines/vite-engine.spec.ts +358 -0
- package/tests/infra/result-collector.spec.ts +46 -0
- package/tests/infra/signal-handler.spec.ts +32 -0
- package/tests/infra/worker-manager.spec.ts +63 -0
- package/tests/orchestrators/build-orchestrator.spec.ts +772 -0
- package/tests/orchestrators/dev-watch-orchestrator.spec.ts +1173 -0
- package/tests/sd-cli-entry.spec.ts +49 -0
- package/tests/utils/angular-build.spec.ts +251 -0
- package/tests/utils/build-env.spec.ts +33 -0
- package/tests/utils/concurrency.spec.ts +65 -0
- package/tests/utils/copy-src.spec.ts +144 -0
- package/tests/utils/esbuild-config.spec.ts +186 -0
- package/tests/utils/external-modules.spec.ts +161 -0
- package/tests/utils/ngtsc-scss-refactor.spec.ts +66 -0
- package/tests/utils/output-path-rewriter.spec.ts +165 -0
- package/tests/utils/output-utils.spec.ts +104 -0
- package/tests/utils/package-utils.spec.ts +52 -0
- package/tests/utils/rebuild-manager.spec.ts +30 -27
- package/tests/utils/replace-deps.spec.ts +69 -0
- package/tests/utils/scss-compiler.spec.ts +131 -0
- package/tests/utils/sd-config.spec.ts +77 -0
- package/tests/utils/tsc-build.spec.ts +358 -0
- package/tests/utils/tsconfig-angular.spec.ts +71 -0
- package/tests/utils/typecheck-non-package.spec.ts +120 -0
- package/tests/utils/worker-events.spec.ts +155 -0
- package/tests/utils/worker-utils.spec.ts +43 -0
- package/tests/vitest-plugin-cwd.spec.ts +68 -0
- package/tests/vitest-plugin.spec.ts +103 -0
- package/tests/workers/library-build-worker.spec.ts +258 -0
- package/tests/workers/ngtsc-build-worker.spec.ts +187 -0
- package/tests/workers/server-build-worker.spec.ts +566 -0
- package/tests/workers/server-runtime-worker.spec.ts +251 -0
- package/README.md +0 -295
- package/dist/builders/BaseBuilder.d.ts +0 -88
- package/dist/builders/BaseBuilder.d.ts.map +0 -1
- package/dist/builders/BaseBuilder.js +0 -142
- package/dist/builders/BaseBuilder.js.map +0 -6
- package/dist/builders/DtsBuilder.d.ts +0 -22
- package/dist/builders/DtsBuilder.d.ts.map +0 -1
- package/dist/builders/DtsBuilder.js +0 -72
- package/dist/builders/DtsBuilder.js.map +0 -6
- package/dist/builders/LibraryBuilder.d.ts +0 -22
- package/dist/builders/LibraryBuilder.d.ts.map +0 -1
- package/dist/builders/LibraryBuilder.js +0 -85
- package/dist/builders/LibraryBuilder.js.map +0 -6
- package/dist/builders/types.d.ts +0 -55
- package/dist/builders/types.d.ts.map +0 -1
- package/dist/builders/types.js +0 -1
- package/dist/builders/types.js.map +0 -6
- package/dist/capacitor/capacitor.d.ts +0 -151
- package/dist/capacitor/capacitor.d.ts.map +0 -1
- package/dist/capacitor/capacitor.js +0 -694
- package/dist/capacitor/capacitor.js.map +0 -6
- package/dist/commands/device.d.ts +0 -22
- package/dist/commands/device.d.ts.map +0 -1
- package/dist/commands/device.js +0 -98
- package/dist/commands/device.js.map +0 -6
- package/dist/commands/init.d.ts +0 -14
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -72
- package/dist/commands/init.js.map +0 -6
- package/dist/electron/electron.d.ts +0 -84
- package/dist/electron/electron.d.ts.map +0 -1
- package/dist/electron/electron.js +0 -263
- package/dist/electron/electron.js.map +0 -6
- package/dist/orchestrators/DevOrchestrator.d.ts +0 -83
- package/dist/orchestrators/DevOrchestrator.d.ts.map +0 -1
- package/dist/orchestrators/DevOrchestrator.js +0 -540
- package/dist/orchestrators/DevOrchestrator.js.map +0 -6
- package/dist/orchestrators/WatchOrchestrator.d.ts +0 -57
- package/dist/orchestrators/WatchOrchestrator.d.ts.map +0 -1
- package/dist/orchestrators/WatchOrchestrator.js +0 -199
- package/dist/orchestrators/WatchOrchestrator.js.map +0 -6
- package/dist/utils/tailwind-config-deps.d.ts +0 -8
- package/dist/utils/tailwind-config-deps.d.ts.map +0 -1
- package/dist/utils/tailwind-config-deps.js +0 -82
- package/dist/utils/tailwind-config-deps.js.map +0 -6
- package/dist/utils/template.d.ts +0 -14
- package/dist/utils/template.d.ts.map +0 -1
- package/dist/utils/template.js +0 -33
- package/dist/utils/template.js.map +0 -6
- package/dist/utils/vite-config.d.ts +0 -35
- package/dist/utils/vite-config.d.ts.map +0 -1
- package/dist/utils/vite-config.js +0 -259
- package/dist/utils/vite-config.js.map +0 -6
- package/dist/workers/client.worker.d.ts +0 -83
- package/dist/workers/client.worker.d.ts.map +0 -1
- package/dist/workers/client.worker.js +0 -111
- package/dist/workers/client.worker.js.map +0 -6
- package/dist/workers/dts.worker.d.ts +0 -75
- package/dist/workers/dts.worker.d.ts.map +0 -1
- package/dist/workers/dts.worker.js +0 -270
- package/dist/workers/dts.worker.js.map +0 -6
- package/dist/workers/library.worker.d.ts +0 -75
- package/dist/workers/library.worker.d.ts.map +0 -1
- package/dist/workers/library.worker.js +0 -166
- package/dist/workers/library.worker.js.map +0 -6
- package/dist/workers/server.worker.d.ts.map +0 -1
- package/dist/workers/server.worker.js +0 -482
- package/dist/workers/server.worker.js.map +0 -6
- package/src/builders/BaseBuilder.ts +0 -218
- package/src/builders/DtsBuilder.ts +0 -92
- package/src/builders/LibraryBuilder.ts +0 -110
- package/src/builders/types.ts +0 -60
- package/src/capacitor/capacitor.ts +0 -931
- package/src/commands/device.ts +0 -140
- package/src/commands/init.ts +0 -113
- package/src/electron/electron.ts +0 -362
- package/src/orchestrators/DevOrchestrator.ts +0 -744
- package/src/orchestrators/WatchOrchestrator.ts +0 -277
- package/src/utils/tailwind-config-deps.ts +0 -98
- package/src/utils/template.ts +0 -56
- package/src/utils/vite-config.ts +0 -390
- package/src/workers/client.worker.ts +0 -250
- package/src/workers/dts.worker.ts +0 -453
- package/src/workers/library.worker.ts +0 -316
- package/src/workers/server.worker.ts +0 -734
- package/templates/init/.gitignore.hbs +0 -34
- package/templates/init/.npmrc.hbs +0 -1
- package/templates/init/.prettierignore +0 -1
- package/templates/init/.prettierrc.yaml +0 -12
- package/templates/init/eslint.config.ts +0 -15
- package/templates/init/mise.toml +0 -3
- package/templates/init/package.json.hbs +0 -32
- package/templates/init/packages/client-admin/index.html.hbs +0 -144
- package/templates/init/packages/client-admin/package.json.hbs +0 -27
- package/templates/init/packages/client-admin/public/assets/logo-landscape.png +0 -0
- package/templates/init/packages/client-admin/public/assets/logo.png +0 -0
- package/templates/init/packages/client-admin/public/favicon.ico +0 -0
- package/templates/init/packages/client-admin/src/App.tsx +0 -42
- package/templates/init/packages/client-admin/src/dev/DevDialog.tsx +0 -34
- package/templates/init/packages/client-admin/src/events/AuthChangeEvent.ts +0 -3
- package/templates/init/packages/client-admin/src/main.css +0 -4
- package/templates/init/packages/client-admin/src/main.tsx.hbs +0 -146
- package/templates/init/packages/client-admin/src/providers/AppServiceProvider.tsx.hbs +0 -103
- package/templates/init/packages/client-admin/src/providers/AppStructureProvider.tsx +0 -84
- package/templates/init/packages/client-admin/src/providers/AuthProvider.tsx.hbs +0 -96
- package/templates/init/packages/client-admin/src/providers/configureSharedData.ts.hbs +0 -67
- package/templates/init/packages/client-admin/src/views/auth/LoginView.tsx +0 -132
- package/templates/init/packages/client-admin/src/views/home/HomeView.tsx +0 -108
- package/templates/init/packages/client-admin/src/views/home/base/employee/EmployeeDetail.tsx.hbs +0 -243
- package/templates/init/packages/client-admin/src/views/home/base/employee/EmployeeSheet.tsx.hbs +0 -271
- package/templates/init/packages/client-admin/src/views/home/base/role-permission/RoleDetail.tsx.hbs +0 -146
- package/templates/init/packages/client-admin/src/views/home/base/role-permission/RolePermissionDetail.tsx.hbs +0 -121
- package/templates/init/packages/client-admin/src/views/home/base/role-permission/RolePermissionView.tsx +0 -52
- package/templates/init/packages/client-admin/src/views/home/base/role-permission/RoleSheet.tsx.hbs +0 -125
- package/templates/init/packages/client-admin/src/views/home/main/MainView.tsx.hbs +0 -13
- package/templates/init/packages/client-admin/src/views/home/my-info/MyInfoDetail.tsx.hbs +0 -241
- package/templates/init/packages/client-admin/src/views/home/system/system-log/SystemLogSheet.tsx.hbs +0 -169
- package/templates/init/packages/client-admin/src/views/not-found/NotFoundView.tsx +0 -15
- package/templates/init/packages/client-admin/tailwind.config.ts +0 -10
- package/templates/init/packages/db-main/package.json.hbs +0 -13
- package/templates/init/packages/db-main/src/MainDbContext.ts +0 -22
- package/templates/init/packages/db-main/src/dataLogExt.ts +0 -127
- package/templates/init/packages/db-main/src/index.ts +0 -14
- package/templates/init/packages/db-main/src/tables/base/Employee.ts +0 -24
- package/templates/init/packages/db-main/src/tables/base/EmployeeConfig.ts +0 -13
- package/templates/init/packages/db-main/src/tables/base/Role.ts +0 -9
- package/templates/init/packages/db-main/src/tables/base/RolePermission.ts +0 -13
- package/templates/init/packages/db-main/src/tables/system/_DataLog.ts +0 -19
- package/templates/init/packages/db-main/src/tables/system/_Log.ts +0 -16
- package/templates/init/packages/server/package.json.hbs +0 -20
- package/templates/init/packages/server/public-dev/dev//354/264/210/352/270/260/355/231/224.xlsx +0 -0
- package/templates/init/packages/server/src/index.ts +0 -4
- package/templates/init/packages/server/src/main.ts.hbs +0 -34
- package/templates/init/packages/server/src/services/AuthService.ts.hbs +0 -171
- package/templates/init/packages/server/src/services/DevService.ts.hbs +0 -94
- package/templates/init/packages/server/src/services/EmployeeService.ts.hbs +0 -122
- package/templates/init/packages/server/src/services/RoleService.ts.hbs +0 -59
- package/templates/init/pnpm-workspace.yaml +0 -15
- package/templates/init/sd.config.ts.hbs +0 -48
- package/templates/init/tsconfig.json.hbs +0 -39
- package/templates/init/vitest.config.ts +0 -36
- package/tests/capacitor-exclude.spec.ts +0 -78
- package/tests/capacitor.spec.ts +0 -49
- package/tests/copy-src.spec.ts +0 -50
- package/tests/electron-exclude.spec.ts +0 -61
- package/tests/get-compiler-options-for-package.spec.ts +0 -80
- package/tests/get-package-source-files.spec.ts +0 -139
- package/tests/get-types-from-package-json.spec.ts +0 -92
- package/tests/infra/ResultCollector.spec.ts +0 -30
- package/tests/infra/SignalHandler.spec.ts +0 -38
- package/tests/infra/WorkerManager.spec.ts +0 -63
- package/tests/load-ignore-patterns.spec.ts +0 -163
- package/tests/load-sd-config.spec.ts +0 -100
- package/tests/package-utils.spec.ts +0 -188
- package/tests/parse-root-tsconfig.spec.ts +0 -89
- package/tests/publish-config-narrowing.spec.ts +0 -20
- package/tests/replace-deps.spec.ts +0 -308
- package/tests/run-lint.spec.ts +0 -366
- package/tests/run-typecheck.spec.ts +0 -544
- package/tests/run-watch.spec.ts +0 -76
- package/tests/sd-cli.spec.ts +0 -265
- package/tests/sd-public-dev-plugin-mime.spec.ts +0 -19
- package/tests/tailwind-config-deps.spec.ts +0 -30
- package/tests/template.spec.ts +0 -70
- package/tests/vite-config-exclude.spec.ts +0 -35
- package/tests/vite-config-outdir.spec.ts +0 -38
- package/tests/write-changed-output-files.spec.ts +0 -97
package/src/utils/vite-config.ts
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { createRequire } from "module";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import type { Plugin, UserConfig as ViteUserConfig } from "vite";
|
|
5
|
-
import tsconfigPaths from "vite-tsconfig-paths";
|
|
6
|
-
import solidPlugin from "vite-plugin-solid";
|
|
7
|
-
import { VitePWA } from "vite-plugin-pwa";
|
|
8
|
-
import tailwindcss from "tailwindcss";
|
|
9
|
-
import type esbuild from "esbuild";
|
|
10
|
-
import { getTailwindConfigDeps } from "./tailwind-config-deps.js";
|
|
11
|
-
import { FsWatcher, pathx } from "@simplysm/core-node";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Vite plugin that watches scope package dependencies of a Tailwind config.
|
|
15
|
-
*
|
|
16
|
-
* Tailwind CSS's built-in dependency tracking only handles relative path imports,
|
|
17
|
-
* so it cannot detect config changes in scope packages referenced via presets.
|
|
18
|
-
* This plugin watches those files and invalidates the Tailwind cache on change.
|
|
19
|
-
*/
|
|
20
|
-
function sdTailwindConfigDepsPlugin(pkgDir: string, replaceDeps: string[]): Plugin {
|
|
21
|
-
return {
|
|
22
|
-
name: "sd-tailwind-config-deps",
|
|
23
|
-
configureServer(server) {
|
|
24
|
-
const configPath = path.join(pkgDir, "tailwind.config.ts");
|
|
25
|
-
if (!fs.existsSync(configPath)) return;
|
|
26
|
-
|
|
27
|
-
const allDeps = getTailwindConfigDeps(configPath, replaceDeps);
|
|
28
|
-
const configAbsolute = path.resolve(configPath);
|
|
29
|
-
const externalDeps = allDeps.filter((d) => d !== configAbsolute);
|
|
30
|
-
if (externalDeps.length === 0) return;
|
|
31
|
-
|
|
32
|
-
for (const dep of externalDeps) {
|
|
33
|
-
server.watcher.add(dep);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
server.watcher.on("change", (changed) => {
|
|
37
|
-
if (externalDeps.some((d) => pathx.norm(d) === pathx.norm(changed))) {
|
|
38
|
-
// Clear require cache used by jiti (Tailwind's config loader)
|
|
39
|
-
// so changed files are re-read on config reload
|
|
40
|
-
const _require = createRequire(import.meta.url);
|
|
41
|
-
for (const dep of allDeps) {
|
|
42
|
-
delete _require.cache[dep];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Invalidate Tailwind cache: update config mtime to trigger reload
|
|
46
|
-
const now = new Date();
|
|
47
|
-
fs.utimesSync(configPath, now, now);
|
|
48
|
-
server.ws.send({ type: "full-reload" });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check if a package is subpath-only export (no "." in exports field)
|
|
57
|
-
*
|
|
58
|
-
* e.g., @tiptap/pm only exports "./state", "./view" etc., so pre-bundling is not possible.
|
|
59
|
-
* Tries two paths in pnpm structure:
|
|
60
|
-
* 1. Follow realpath to find in .pnpm node_modules
|
|
61
|
-
* 2. Fallback to symlinked workspace package's node_modules
|
|
62
|
-
*/
|
|
63
|
-
function isSubpathOnlyPackage(pkgJsonPath: string): boolean {
|
|
64
|
-
try {
|
|
65
|
-
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")) as {
|
|
66
|
-
exports?: Record<string, unknown> | string;
|
|
67
|
-
main?: string;
|
|
68
|
-
module?: string;
|
|
69
|
-
};
|
|
70
|
-
if (
|
|
71
|
-
pkgJson.exports != null &&
|
|
72
|
-
typeof pkgJson.exports === "object" &&
|
|
73
|
-
!("." in pkgJson.exports) &&
|
|
74
|
-
pkgJson.main == null &&
|
|
75
|
-
pkgJson.module == null
|
|
76
|
-
) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
// Return false on read failure (include in pre-bundling)
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Common MIME types for web assets served from public-dev/ */
|
|
86
|
-
const MIME_TYPES: Record<string, string> = {
|
|
87
|
-
".html": "text/html",
|
|
88
|
-
".css": "text/css",
|
|
89
|
-
".js": "text/javascript",
|
|
90
|
-
".mjs": "text/javascript",
|
|
91
|
-
".json": "application/json",
|
|
92
|
-
".png": "image/png",
|
|
93
|
-
".jpg": "image/jpeg",
|
|
94
|
-
".jpeg": "image/jpeg",
|
|
95
|
-
".gif": "image/gif",
|
|
96
|
-
".svg": "image/svg+xml",
|
|
97
|
-
".ico": "image/x-icon",
|
|
98
|
-
".webp": "image/webp",
|
|
99
|
-
".avif": "image/avif",
|
|
100
|
-
".woff": "font/woff",
|
|
101
|
-
".woff2": "font/woff2",
|
|
102
|
-
".ttf": "font/ttf",
|
|
103
|
-
".mp4": "video/mp4",
|
|
104
|
-
".webm": "video/webm",
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/** @internal Exported for testing */
|
|
108
|
-
export function getMimeType(ext: string): string {
|
|
109
|
-
return MIME_TYPES[ext.toLowerCase()] ?? "application/octet-stream";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Vite plugin that serves files from public-dev/ directory with priority over public/ in dev mode.
|
|
114
|
-
* Keeps Vite's default publicDir (public/) while giving precedence to public-dev/ files at the same path.
|
|
115
|
-
*/
|
|
116
|
-
function sdPublicDevPlugin(pkgDir: string): Plugin {
|
|
117
|
-
const publicDevDir = path.join(pkgDir, "public-dev");
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
name: "sd-public-dev",
|
|
121
|
-
configureServer(server) {
|
|
122
|
-
if (!fs.existsSync(publicDevDir)) return;
|
|
123
|
-
|
|
124
|
-
// Check public-dev/ files before Vite's default static serving
|
|
125
|
-
server.middlewares.use((req, res, next) => {
|
|
126
|
-
if (req.url == null) {
|
|
127
|
-
next();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Strip base path
|
|
132
|
-
const base = server.config.base || "/";
|
|
133
|
-
let urlPath = req.url.split("?")[0];
|
|
134
|
-
if (urlPath.startsWith(base)) {
|
|
135
|
-
urlPath = urlPath.slice(base.length);
|
|
136
|
-
}
|
|
137
|
-
if (urlPath.startsWith("/")) {
|
|
138
|
-
urlPath = urlPath.slice(1);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Path traversal defense: block access to files outside publicDevDir
|
|
142
|
-
const decodedPath = decodeURIComponent(urlPath);
|
|
143
|
-
const filePath = path.resolve(publicDevDir, decodedPath);
|
|
144
|
-
const normalizedRoot = path.resolve(publicDevDir);
|
|
145
|
-
if (!filePath.startsWith(normalizedRoot + path.sep) && filePath !== normalizedRoot) {
|
|
146
|
-
next();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
|
|
151
|
-
const ext = path.extname(filePath);
|
|
152
|
-
res.setHeader("Content-Type", getMimeType(ext));
|
|
153
|
-
const stream = fs.createReadStream(filePath);
|
|
154
|
-
stream.on("error", () => {
|
|
155
|
-
if (!res.headersSent) {
|
|
156
|
-
next();
|
|
157
|
-
} else {
|
|
158
|
-
res.destroy();
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
stream.pipe(res);
|
|
162
|
-
} else {
|
|
163
|
-
next();
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Vite plugin that detects changes in scope packages' dist directories.
|
|
172
|
-
*
|
|
173
|
-
* Vite excludes node_modules from watch by default, so dist file changes
|
|
174
|
-
* in scope packages do not trigger HMR/rebuild.
|
|
175
|
-
* This plugin uses a separate FsWatcher to monitor scope packages' dist directories
|
|
176
|
-
* and triggers Vite's internal HMR pipeline on change.
|
|
177
|
-
* Excludes from optimizeDeps to prevent changes being ignored due to pre-bundled cache.
|
|
178
|
-
*/
|
|
179
|
-
function sdScopeWatchPlugin(
|
|
180
|
-
pkgDir: string,
|
|
181
|
-
replaceDeps: string[],
|
|
182
|
-
onScopeRebuild?: () => void,
|
|
183
|
-
): Plugin {
|
|
184
|
-
return {
|
|
185
|
-
name: "sd-scope-watch",
|
|
186
|
-
config() {
|
|
187
|
-
const excluded: string[] = [];
|
|
188
|
-
const nestedDepsToInclude: string[] = [];
|
|
189
|
-
|
|
190
|
-
for (const pkg of replaceDeps) {
|
|
191
|
-
excluded.push(pkg);
|
|
192
|
-
|
|
193
|
-
const pkgParts = pkg.split("/");
|
|
194
|
-
const depPkgJsonPath = path.join(pkgDir, "node_modules", ...pkgParts, "package.json");
|
|
195
|
-
try {
|
|
196
|
-
const depPkgJson = JSON.parse(fs.readFileSync(depPkgJsonPath, "utf-8")) as {
|
|
197
|
-
dependencies?: Record<string, string>;
|
|
198
|
-
};
|
|
199
|
-
for (const dep of Object.keys(depPkgJson.dependencies ?? {})) {
|
|
200
|
-
if (replaceDeps.includes(dep)) continue;
|
|
201
|
-
if (dep === "solid-js" || dep.startsWith("@solidjs/") || dep.startsWith("solid-"))
|
|
202
|
-
continue;
|
|
203
|
-
if (dep === "tailwindcss") continue;
|
|
204
|
-
|
|
205
|
-
const realPkgPath = fs.realpathSync(path.join(pkgDir, "node_modules", ...pkgParts));
|
|
206
|
-
const pnpmNodeModules = path.resolve(realPkgPath, "../..");
|
|
207
|
-
const depPkgJsonResolved = path.join(pnpmNodeModules, dep, "package.json");
|
|
208
|
-
if (isSubpathOnlyPackage(depPkgJsonResolved)) continue;
|
|
209
|
-
|
|
210
|
-
const depPkgJsonFallback = path.join(
|
|
211
|
-
pkgDir,
|
|
212
|
-
"node_modules",
|
|
213
|
-
...pkgParts,
|
|
214
|
-
"node_modules",
|
|
215
|
-
dep,
|
|
216
|
-
"package.json",
|
|
217
|
-
);
|
|
218
|
-
if (isSubpathOnlyPackage(depPkgJsonFallback)) continue;
|
|
219
|
-
|
|
220
|
-
nestedDepsToInclude.push(`${pkg} > ${dep}`);
|
|
221
|
-
}
|
|
222
|
-
} catch {
|
|
223
|
-
// Skip on package.json read failure
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
optimizeDeps: {
|
|
229
|
-
force: true,
|
|
230
|
-
exclude: excluded,
|
|
231
|
-
include: [...new Set(nestedDepsToInclude)],
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
},
|
|
235
|
-
async configureServer(server) {
|
|
236
|
-
const watchPaths: string[] = [];
|
|
237
|
-
|
|
238
|
-
for (const pkg of replaceDeps) {
|
|
239
|
-
const pkgParts = pkg.split("/");
|
|
240
|
-
const pkgRoot = path.join(pkgDir, "node_modules", ...pkgParts);
|
|
241
|
-
if (!fs.existsSync(pkgRoot)) continue;
|
|
242
|
-
|
|
243
|
-
const distDir = path.join(pkgRoot, "dist");
|
|
244
|
-
if (fs.existsSync(distDir)) {
|
|
245
|
-
watchPaths.push(distDir);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
for (const file of fs.readdirSync(pkgRoot)) {
|
|
249
|
-
if (
|
|
250
|
-
file.endsWith(".css") ||
|
|
251
|
-
file === "tailwind.config.ts" ||
|
|
252
|
-
file === "tailwind.config.js"
|
|
253
|
-
) {
|
|
254
|
-
watchPaths.push(path.join(pkgRoot, file));
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (watchPaths.length === 0) return;
|
|
260
|
-
|
|
261
|
-
const scopeWatcher = await FsWatcher.watch(watchPaths);
|
|
262
|
-
scopeWatcher.onChange({ delay: 300 }, (changeInfos) => {
|
|
263
|
-
for (const { path: changedPath } of changeInfos) {
|
|
264
|
-
let realPath: string;
|
|
265
|
-
try {
|
|
266
|
-
realPath = fs.realpathSync(changedPath);
|
|
267
|
-
} catch {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
server.watcher.emit("change", realPath);
|
|
271
|
-
}
|
|
272
|
-
onScopeRebuild?.();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
server.httpServer?.on("close", () => void scopeWatcher.close());
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Vite config generation options
|
|
282
|
-
*/
|
|
283
|
-
export interface ViteConfigOptions {
|
|
284
|
-
pkgDir: string;
|
|
285
|
-
name: string;
|
|
286
|
-
tsconfigPath: string;
|
|
287
|
-
compilerOptions: Record<string, unknown>;
|
|
288
|
-
env?: Record<string, string>;
|
|
289
|
-
mode: "build" | "dev";
|
|
290
|
-
/** Server port in dev mode (0 for auto-assign) */
|
|
291
|
-
serverPort?: number;
|
|
292
|
-
/** Array of replaceDeps package names (resolved state) */
|
|
293
|
-
replaceDeps?: string[];
|
|
294
|
-
/** Callback when replaceDeps package dist changes */
|
|
295
|
-
onScopeRebuild?: () => void;
|
|
296
|
-
/** Override build.outDir (e.g. ".capacitor/www" for Capacitor builds) */
|
|
297
|
-
outDir?: string;
|
|
298
|
-
/** Override base path (e.g. "./" for Capacitor builds) */
|
|
299
|
-
base?: string;
|
|
300
|
-
/** Packages to exclude from Vite optimizeDeps pre-bundling */
|
|
301
|
-
exclude?: string[];
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Create Vite config
|
|
306
|
-
*
|
|
307
|
-
* Configuration for building/dev server for client packages based on SolidJS + TailwindCSS.
|
|
308
|
-
* - build mode: production build (logLevel: silent)
|
|
309
|
-
* - dev mode: dev server (env substitution via define, server configuration)
|
|
310
|
-
*/
|
|
311
|
-
export function createViteConfig(options: ViteConfigOptions): ViteUserConfig {
|
|
312
|
-
const { pkgDir, name, tsconfigPath, compilerOptions, env, mode, serverPort, replaceDeps } =
|
|
313
|
-
options;
|
|
314
|
-
|
|
315
|
-
// Read package.json to extract app name for PWA manifest
|
|
316
|
-
const pkgJsonPath = path.join(pkgDir, "package.json");
|
|
317
|
-
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")) as { name: string };
|
|
318
|
-
const appName = pkgJson.name.replace(/^@[^/]+\//, "");
|
|
319
|
-
|
|
320
|
-
// Process.env substitution (applied to both build and dev modes)
|
|
321
|
-
const envDefine: Record<string, string> = {};
|
|
322
|
-
if (env != null) {
|
|
323
|
-
envDefine["process.env"] = JSON.stringify(env);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const config: ViteUserConfig = {
|
|
327
|
-
root: pkgDir,
|
|
328
|
-
base: options.base ?? `/${name}/`,
|
|
329
|
-
plugins: [
|
|
330
|
-
tsconfigPaths({ projects: [tsconfigPath] }),
|
|
331
|
-
solidPlugin(),
|
|
332
|
-
VitePWA({
|
|
333
|
-
registerType: "prompt",
|
|
334
|
-
injectRegister: "script",
|
|
335
|
-
manifest: {
|
|
336
|
-
name: appName,
|
|
337
|
-
short_name: appName,
|
|
338
|
-
display: "standalone",
|
|
339
|
-
theme_color: "#ffffff",
|
|
340
|
-
background_color: "#ffffff",
|
|
341
|
-
},
|
|
342
|
-
workbox: {
|
|
343
|
-
globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"],
|
|
344
|
-
},
|
|
345
|
-
}),
|
|
346
|
-
...(replaceDeps != null && replaceDeps.length > 0
|
|
347
|
-
? [sdTailwindConfigDepsPlugin(pkgDir, replaceDeps)]
|
|
348
|
-
: []),
|
|
349
|
-
...(replaceDeps != null && replaceDeps.length > 0
|
|
350
|
-
? [sdScopeWatchPlugin(pkgDir, replaceDeps, options.onScopeRebuild)]
|
|
351
|
-
: []),
|
|
352
|
-
...(mode === "dev" ? [sdPublicDevPlugin(pkgDir)] : []),
|
|
353
|
-
],
|
|
354
|
-
css: {
|
|
355
|
-
postcss: {
|
|
356
|
-
plugins: [tailwindcss({ config: path.join(pkgDir, "tailwind.config.ts") })],
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
esbuild: {
|
|
360
|
-
tsconfigRaw: { compilerOptions: compilerOptions as esbuild.TsconfigRaw["compilerOptions"] },
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
// Process.env substitution (applied to both build and dev modes)
|
|
365
|
-
config.define = envDefine;
|
|
366
|
-
|
|
367
|
-
if (options.outDir != null) {
|
|
368
|
-
config.build = { outDir: options.outDir };
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (options.exclude != null && options.exclude.length > 0) {
|
|
372
|
-
config.optimizeDeps = { exclude: options.exclude };
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (mode === "build") {
|
|
376
|
-
config.logLevel = "silent";
|
|
377
|
-
} else {
|
|
378
|
-
// Dev mode
|
|
379
|
-
config.server = {
|
|
380
|
-
// serverPort === 0: server-connected client (proxy target)
|
|
381
|
-
// → explicitly set host to 127.0.0.1 to ensure IPv4 binding
|
|
382
|
-
// (On Windows, if localhost resolves to ::1 (IPv6), proxy connection to 127.0.0.1 causes ECONNREFUSED)
|
|
383
|
-
host: serverPort === 0 ? "127.0.0.1" : undefined,
|
|
384
|
-
port: serverPort === 0 ? undefined : serverPort,
|
|
385
|
-
strictPort: serverPort !== 0 && serverPort !== undefined,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return config;
|
|
390
|
-
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { build as viteBuild, createServer, type ViteDevServer } from "vite";
|
|
4
|
-
import { createWorker } from "@simplysm/core-node";
|
|
5
|
-
import { err as errNs } from "@simplysm/core-common";
|
|
6
|
-
import { consola } from "consola";
|
|
7
|
-
import type { SdClientPackageConfig } from "../sd-config.types";
|
|
8
|
-
import { parseRootTsconfig, getCompilerOptionsForPackage } from "../utils/tsconfig";
|
|
9
|
-
import { createViteConfig } from "../utils/vite-config";
|
|
10
|
-
import { collectDeps } from "../utils/package-utils";
|
|
11
|
-
import { registerCleanupHandlers, createOnceGuard, applyDebugLevel } from "../utils/worker-utils";
|
|
12
|
-
|
|
13
|
-
applyDebugLevel();
|
|
14
|
-
|
|
15
|
-
//#region Types
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Client build information (for one-time build)
|
|
19
|
-
*/
|
|
20
|
-
export interface ClientBuildInfo {
|
|
21
|
-
name: string;
|
|
22
|
-
config: SdClientPackageConfig;
|
|
23
|
-
cwd: string;
|
|
24
|
-
pkgDir: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Client build result
|
|
29
|
-
*/
|
|
30
|
-
export interface ClientBuildResult {
|
|
31
|
-
success: boolean;
|
|
32
|
-
errors?: string[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Client watch information
|
|
37
|
-
*/
|
|
38
|
-
export interface ClientWatchInfo {
|
|
39
|
-
name: string;
|
|
40
|
-
config: SdClientPackageConfig;
|
|
41
|
-
cwd: string;
|
|
42
|
-
pkgDir: string;
|
|
43
|
-
/** replaceDeps configuration from sd.config.ts */
|
|
44
|
-
replaceDeps?: Record<string, string>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Build event
|
|
49
|
-
*/
|
|
50
|
-
export interface ClientBuildEvent {
|
|
51
|
-
success: boolean;
|
|
52
|
-
errors?: string[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Server ready event
|
|
57
|
-
*/
|
|
58
|
-
export interface ClientServerReadyEvent {
|
|
59
|
-
port: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Error event
|
|
64
|
-
*/
|
|
65
|
-
export interface ClientErrorEvent {
|
|
66
|
-
message: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Worker event types
|
|
71
|
-
*/
|
|
72
|
-
export interface ClientWorkerEvents extends Record<string, unknown> {
|
|
73
|
-
buildStart: Record<string, never>;
|
|
74
|
-
build: ClientBuildEvent;
|
|
75
|
-
serverReady: ClientServerReadyEvent;
|
|
76
|
-
error: ClientErrorEvent;
|
|
77
|
-
scopeRebuild: Record<string, never>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
|
|
82
|
-
//#region Resource Management
|
|
83
|
-
|
|
84
|
-
const logger = consola.withTag("sd:cli:client:worker");
|
|
85
|
-
|
|
86
|
-
/** Vite dev server (to be cleaned up) */
|
|
87
|
-
let viteServer: ViteDevServer | undefined;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Clean up resources
|
|
91
|
-
*/
|
|
92
|
-
async function cleanup(): Promise<void> {
|
|
93
|
-
// Capture global variable to temporary variable and initialize
|
|
94
|
-
// (other calls can modify global variable while Promise.all is waiting)
|
|
95
|
-
const serverToClose = viteServer;
|
|
96
|
-
viteServer = undefined;
|
|
97
|
-
|
|
98
|
-
if (serverToClose != null) {
|
|
99
|
-
await serverToClose.close();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Clean up resources before process termination (SIGTERM/SIGINT)
|
|
104
|
-
// Note: worker.terminate() terminates immediately without calling these handlers.
|
|
105
|
-
// However, normal shutdown in watch mode is done through SIGINT/SIGTERM of main process, so no issues.
|
|
106
|
-
registerCleanupHandlers(cleanup, logger);
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
|
|
110
|
-
//#region Worker
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* One-time build
|
|
114
|
-
*/
|
|
115
|
-
async function build(info: ClientBuildInfo): Promise<ClientBuildResult> {
|
|
116
|
-
try {
|
|
117
|
-
// Parse tsconfig
|
|
118
|
-
const parsedConfig = parseRootTsconfig(info.cwd);
|
|
119
|
-
const tsconfigPath = path.join(info.cwd, "tsconfig.json");
|
|
120
|
-
|
|
121
|
-
// Create compilerOptions for browser target
|
|
122
|
-
const compilerOptions = await getCompilerOptionsForPackage(
|
|
123
|
-
parsedConfig.options,
|
|
124
|
-
"browser",
|
|
125
|
-
info.pkgDir,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// Create Vite configuration and build
|
|
129
|
-
const isCapacitor = info.config.capacitor != null;
|
|
130
|
-
const outDir = isCapacitor
|
|
131
|
-
? path.join(info.pkgDir, ".capacitor", "www")
|
|
132
|
-
: undefined;
|
|
133
|
-
|
|
134
|
-
const viteConfig = createViteConfig({
|
|
135
|
-
pkgDir: info.pkgDir,
|
|
136
|
-
name: info.name,
|
|
137
|
-
tsconfigPath,
|
|
138
|
-
compilerOptions,
|
|
139
|
-
env: info.config.env,
|
|
140
|
-
mode: "build",
|
|
141
|
-
outDir,
|
|
142
|
-
base: isCapacitor ? "./" : undefined,
|
|
143
|
-
exclude: info.config.exclude,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
await viteBuild(viteConfig);
|
|
147
|
-
|
|
148
|
-
// Generate .config.json
|
|
149
|
-
const confDistDir = outDir ?? path.join(info.pkgDir, "dist");
|
|
150
|
-
const confDistPath = path.join(confDistDir, ".config.json");
|
|
151
|
-
fs.writeFileSync(confDistPath, JSON.stringify(info.config.configs ?? {}, undefined, 2));
|
|
152
|
-
|
|
153
|
-
return { success: true };
|
|
154
|
-
} catch (err) {
|
|
155
|
-
return {
|
|
156
|
-
success: false,
|
|
157
|
-
errors: [errNs.message(err)],
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const guardStartWatch = createOnceGuard("startWatch");
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Start watch (Vite dev server)
|
|
166
|
-
* @remarks This function should be called only once per worker.
|
|
167
|
-
* @throws If watch is already started
|
|
168
|
-
*/
|
|
169
|
-
async function startWatch(info: ClientWatchInfo): Promise<void> {
|
|
170
|
-
guardStartWatch();
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
// Parse tsconfig
|
|
174
|
-
const parsedConfig = parseRootTsconfig(info.cwd);
|
|
175
|
-
const tsconfigPath = path.join(info.cwd, "tsconfig.json");
|
|
176
|
-
|
|
177
|
-
// Create compilerOptions for browser target
|
|
178
|
-
const compilerOptions = await getCompilerOptionsForPackage(
|
|
179
|
-
parsedConfig.options,
|
|
180
|
-
"browser",
|
|
181
|
-
info.pkgDir,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// If server is 0, auto-assign port (server-connected client)
|
|
185
|
-
// If server is a number, use that port (standalone client)
|
|
186
|
-
const serverPort = typeof info.config.server === "number" ? info.config.server : 0;
|
|
187
|
-
|
|
188
|
-
// Collect replaceDeps based on dependencies
|
|
189
|
-
const { replaceDeps } = collectDeps(info.pkgDir, info.cwd, info.replaceDeps);
|
|
190
|
-
|
|
191
|
-
// Create Vite configuration
|
|
192
|
-
const viteConfig = createViteConfig({
|
|
193
|
-
pkgDir: info.pkgDir,
|
|
194
|
-
name: info.name,
|
|
195
|
-
tsconfigPath,
|
|
196
|
-
compilerOptions,
|
|
197
|
-
env: info.config.env,
|
|
198
|
-
mode: "dev",
|
|
199
|
-
serverPort,
|
|
200
|
-
replaceDeps,
|
|
201
|
-
onScopeRebuild: () => sender.send("scopeRebuild", {}),
|
|
202
|
-
exclude: info.config.exclude,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
// Start Vite dev server
|
|
206
|
-
viteServer = await createServer(viteConfig);
|
|
207
|
-
await viteServer.listen();
|
|
208
|
-
|
|
209
|
-
// Generate .config.json
|
|
210
|
-
const confDistPath = path.join(info.pkgDir, "dist", ".config.json");
|
|
211
|
-
fs.mkdirSync(path.dirname(confDistPath), { recursive: true });
|
|
212
|
-
fs.writeFileSync(confDistPath, JSON.stringify(info.config.configs ?? {}, undefined, 2));
|
|
213
|
-
|
|
214
|
-
// Get actual assigned port (config.server.port is the configured value, so get actual port from httpServer)
|
|
215
|
-
const address = viteServer.httpServer?.address();
|
|
216
|
-
const actualPort = typeof address === "object" && address != null ? address.port : undefined;
|
|
217
|
-
|
|
218
|
-
if (actualPort == null) {
|
|
219
|
-
sender.send("error", { message: "Unable to determine Vite dev server port." });
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
sender.send("serverReady", { port: actualPort });
|
|
224
|
-
} catch (err) {
|
|
225
|
-
sender.send("error", {
|
|
226
|
-
message: errNs.message(err),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Stop watch
|
|
233
|
-
* @remarks Clean up Vite dev server.
|
|
234
|
-
*/
|
|
235
|
-
async function stopWatch(): Promise<void> {
|
|
236
|
-
await cleanup();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const sender = createWorker<
|
|
240
|
-
{ build: typeof build; startWatch: typeof startWatch; stopWatch: typeof stopWatch },
|
|
241
|
-
ClientWorkerEvents
|
|
242
|
-
>({
|
|
243
|
-
build,
|
|
244
|
-
startWatch,
|
|
245
|
-
stopWatch,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
export default sender;
|
|
249
|
-
|
|
250
|
-
//#endregion
|