@pie-element/cli 0.1.1 → 0.1.2-next.0
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/README.md +48 -10
- package/dist/commands/dev/demo/index.d.ts +1 -1
- package/dist/commands/dev/demo/index.js +21 -0
- package/dist/commands/dev/demo/index.js.map +1 -1
- package/dist/commands/dev/test-bundler.d.ts +0 -1
- package/dist/commands/dev/test-bundler.js +2 -10
- package/dist/commands/dev/test-bundler.js.map +1 -1
- package/dist/commands/docs/generate.d.ts +16 -0
- package/dist/commands/docs/generate.js +150 -0
- package/dist/commands/docs/generate.js.map +1 -0
- package/dist/commands/docs/verify.d.ts +12 -0
- package/dist/commands/docs/verify.js +40 -0
- package/dist/commands/docs/verify.js.map +1 -0
- package/dist/commands/packages/create-controllers.d.ts +0 -1
- package/dist/commands/packages/create-controllers.js.map +1 -1
- package/dist/commands/packages/create-lib-react.d.ts +0 -1
- package/dist/commands/packages/create-lib-react.js +1 -3
- package/dist/commands/packages/create-lib-react.js.map +1 -1
- package/dist/commands/packages/create-react-elements.d.ts +0 -1
- package/dist/commands/packages/create-react-elements.js +2 -3
- package/dist/commands/packages/create-react-elements.js.map +1 -1
- package/dist/commands/packages/enable-publishing.d.ts +0 -1
- package/dist/commands/packages/enable-publishing.js +26 -23
- package/dist/commands/packages/enable-publishing.js.map +1 -1
- package/dist/commands/packages/init-synced-elements.d.ts +0 -1
- package/dist/commands/packages/init-synced-elements.js +1 -1
- package/dist/commands/packages/init-synced-elements.js.map +1 -1
- package/dist/commands/upstream/analyze-esm.d.ts +0 -1
- package/dist/commands/upstream/analyze-esm.js +5 -1
- package/dist/commands/upstream/analyze-esm.js.map +1 -1
- package/dist/commands/upstream/check.d.ts +0 -1
- package/dist/commands/upstream/check.js.map +1 -1
- package/dist/commands/upstream/deps.d.ts +0 -1
- package/dist/commands/upstream/deps.js.map +1 -1
- package/dist/commands/upstream/sync.d.ts +11 -2
- package/dist/commands/upstream/sync.js +364 -25
- package/dist/commands/upstream/sync.js.map +1 -1
- package/dist/commands/upstream/track.d.ts +0 -1
- package/dist/commands/upstream/track.js.map +1 -1
- package/dist/commands/upstream/update.d.ts +0 -1
- package/dist/commands/upstream/update.js +37 -7
- package/dist/commands/upstream/update.js.map +1 -1
- package/dist/commands/verify/controllers.d.ts +0 -1
- package/dist/commands/verify/controllers.js +213 -59
- package/dist/commands/verify/controllers.js.map +1 -1
- package/dist/commands/verify/dependency-integrity.d.ts +18 -0
- package/dist/commands/verify/dependency-integrity.js +147 -0
- package/dist/commands/verify/dependency-integrity.js.map +1 -0
- package/dist/commands/verify/react-build.d.ts +0 -1
- package/dist/commands/verify/react-build.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/docs/contract-validator.d.ts +12 -0
- package/dist/lib/docs/contract-validator.js +38 -0
- package/dist/lib/docs/contract-validator.js.map +1 -0
- package/dist/lib/docs/contracts.d.ts +11 -0
- package/dist/lib/docs/contracts.js +241 -0
- package/dist/lib/docs/contracts.js.map +1 -0
- package/dist/lib/docs/discovery.d.ts +10 -0
- package/dist/lib/docs/discovery.js +91 -0
- package/dist/lib/docs/discovery.js.map +1 -0
- package/dist/lib/docs/generator.d.ts +14 -0
- package/dist/lib/docs/generator.js +450 -0
- package/dist/lib/docs/generator.js.map +1 -0
- package/dist/lib/docs/source-extractor.d.ts +2 -0
- package/dist/lib/docs/source-extractor.js +209 -0
- package/dist/lib/docs/source-extractor.js.map +1 -0
- package/dist/lib/docs/types.d.ts +77 -0
- package/dist/lib/docs/types.js +2 -0
- package/dist/lib/docs/types.js.map +1 -0
- package/dist/lib/upstream/repo-utils.d.ts +0 -1
- package/dist/lib/upstream/repo-utils.js.map +1 -1
- package/dist/lib/upstream/sync-compatibility.d.ts +0 -1
- package/dist/lib/upstream/sync-compatibility.js.map +1 -1
- package/dist/lib/upstream/sync-constants.d.ts +35 -7
- package/dist/lib/upstream/sync-constants.js +40 -11
- package/dist/lib/upstream/sync-constants.js.map +1 -1
- package/dist/lib/upstream/sync-controllers-strategy.d.ts +0 -1
- package/dist/lib/upstream/sync-controllers-strategy.js +14 -4
- package/dist/lib/upstream/sync-controllers-strategy.js.map +1 -1
- package/dist/lib/upstream/sync-demo-metadata.d.ts +0 -1
- package/dist/lib/upstream/sync-demo-metadata.js +1 -1
- package/dist/lib/upstream/sync-demo-metadata.js.map +1 -1
- package/dist/lib/upstream/sync-entry-discovery.d.ts +3 -0
- package/dist/lib/upstream/sync-entry-discovery.js +23 -0
- package/dist/lib/upstream/sync-entry-discovery.js.map +1 -0
- package/dist/lib/upstream/sync-externals.d.ts +7 -7
- package/dist/lib/upstream/sync-externals.js +51 -35
- package/dist/lib/upstream/sync-externals.js.map +1 -1
- package/dist/lib/upstream/sync-filesystem.d.ts +0 -1
- package/dist/lib/upstream/sync-filesystem.js.map +1 -1
- package/dist/lib/upstream/sync-imports.d.ts +82 -62
- package/dist/lib/upstream/sync-imports.js +658 -185
- package/dist/lib/upstream/sync-imports.js.map +1 -1
- package/dist/lib/upstream/sync-package-json.d.ts +0 -1
- package/dist/lib/upstream/sync-package-json.js +7 -0
- package/dist/lib/upstream/sync-package-json.js.map +1 -1
- package/dist/lib/upstream/sync-package-manager.d.ts +14 -4
- package/dist/lib/upstream/sync-package-manager.js +405 -72
- package/dist/lib/upstream/sync-package-manager.js.map +1 -1
- package/dist/lib/upstream/sync-pielib-strategy.d.ts +2 -1
- package/dist/lib/upstream/sync-pielib-strategy.js +228 -110
- package/dist/lib/upstream/sync-pielib-strategy.js.map +1 -1
- package/dist/lib/upstream/sync-presets.d.ts +52 -0
- package/dist/lib/upstream/sync-presets.js +175 -0
- package/dist/lib/upstream/sync-presets.js.map +1 -0
- package/dist/lib/upstream/sync-react-strategy.d.ts +6 -1
- package/dist/lib/upstream/sync-react-strategy.js +342 -134
- package/dist/lib/upstream/sync-react-strategy.js.map +1 -1
- package/dist/lib/upstream/sync-source-edit.d.ts +14 -0
- package/dist/lib/upstream/sync-source-edit.js +89 -0
- package/dist/lib/upstream/sync-source-edit.js.map +1 -0
- package/dist/lib/upstream/sync-source-tree.d.ts +22 -0
- package/dist/lib/upstream/sync-source-tree.js +99 -0
- package/dist/lib/upstream/sync-source-tree.js.map +1 -0
- package/dist/lib/upstream/sync-strategy.d.ts +1 -1
- package/dist/lib/upstream/sync-strategy.js.map +1 -1
- package/dist/lib/upstream/sync-summary.d.ts +0 -1
- package/dist/lib/upstream/sync-summary.js.map +1 -1
- package/dist/lib/upstream/sync-transforms.d.ts +13 -11
- package/dist/lib/upstream/sync-transforms.js +23 -17
- package/dist/lib/upstream/sync-transforms.js.map +1 -1
- package/dist/lib/upstream/sync-vite-config.d.ts +13 -1
- package/dist/lib/upstream/sync-vite-config.js +65 -46
- package/dist/lib/upstream/sync-vite-config.js.map +1 -1
- package/dist/utils/compatibility.d.ts +13 -1
- package/dist/utils/compatibility.js +143 -2
- package/dist/utils/compatibility.js.map +1 -1
- package/dist/utils/conversion.d.ts +0 -1
- package/dist/utils/conversion.js.map +1 -1
- package/dist/utils/dependency-integrity.d.ts +37 -0
- package/dist/utils/dependency-integrity.js +557 -0
- package/dist/utils/dependency-integrity.js.map +1 -0
- package/dist/utils/git.d.ts +0 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/logger.d.ts +0 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/package-json.d.ts +0 -1
- package/dist/utils/package-json.js.map +1 -1
- package/package.json +25 -8
- package/.compatibility/report.json +0 -2491
- package/.turbo/turbo-build.log +0 -1
- package/CHANGELOG.md +0 -8
- package/REFACTORING.md +0 -131
- package/bin/dev.js +0 -5
- package/dist/commands/dev/demo/index.d.ts.map +0 -1
- package/dist/commands/dev/test-bundler.d.ts.map +0 -1
- package/dist/commands/mathquill/migrate.d.ts +0 -20
- package/dist/commands/mathquill/migrate.d.ts.map +0 -1
- package/dist/commands/mathquill/migrate.js +0 -240
- package/dist/commands/mathquill/migrate.js.map +0 -1
- package/dist/commands/mathquill/status.d.ts +0 -20
- package/dist/commands/mathquill/status.d.ts.map +0 -1
- package/dist/commands/mathquill/status.js +0 -231
- package/dist/commands/mathquill/status.js.map +0 -1
- package/dist/commands/packages/create-controllers.d.ts.map +0 -1
- package/dist/commands/packages/create-lib-react.d.ts.map +0 -1
- package/dist/commands/packages/create-react-elements.d.ts.map +0 -1
- package/dist/commands/packages/enable-publishing.d.ts.map +0 -1
- package/dist/commands/packages/init-synced-elements.d.ts.map +0 -1
- package/dist/commands/upstream/analyze-esm.d.ts.map +0 -1
- package/dist/commands/upstream/check.d.ts.map +0 -1
- package/dist/commands/upstream/deps.d.ts.map +0 -1
- package/dist/commands/upstream/sync-mathquill.d.ts +0 -12
- package/dist/commands/upstream/sync-mathquill.d.ts.map +0 -1
- package/dist/commands/upstream/sync-mathquill.js +0 -97
- package/dist/commands/upstream/sync-mathquill.js.map +0 -1
- package/dist/commands/upstream/sync.d.ts.map +0 -1
- package/dist/commands/upstream/track.d.ts.map +0 -1
- package/dist/commands/upstream/update.d.ts.map +0 -1
- package/dist/commands/verify/controllers.d.ts.map +0 -1
- package/dist/commands/verify/react-build.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/mathquill/extension-generator.d.ts +0 -9
- package/dist/lib/mathquill/extension-generator.d.ts.map +0 -1
- package/dist/lib/mathquill/extension-generator.js +0 -107
- package/dist/lib/mathquill/extension-generator.js.map +0 -1
- package/dist/lib/mathquill/khan-extractor.d.ts +0 -16
- package/dist/lib/mathquill/khan-extractor.d.ts.map +0 -1
- package/dist/lib/mathquill/khan-extractor.js +0 -148
- package/dist/lib/mathquill/khan-extractor.js.map +0 -1
- package/dist/lib/mathquill/learnosity-extractor.d.ts +0 -15
- package/dist/lib/mathquill/learnosity-extractor.d.ts.map +0 -1
- package/dist/lib/mathquill/learnosity-extractor.js +0 -170
- package/dist/lib/mathquill/learnosity-extractor.js.map +0 -1
- package/dist/lib/mathquill/migration-orchestrator.d.ts +0 -77
- package/dist/lib/mathquill/migration-orchestrator.d.ts.map +0 -1
- package/dist/lib/mathquill/migration-orchestrator.js +0 -391
- package/dist/lib/mathquill/migration-orchestrator.js.map +0 -1
- package/dist/lib/mathquill/package-updater.d.ts +0 -9
- package/dist/lib/mathquill/package-updater.d.ts.map +0 -1
- package/dist/lib/mathquill/package-updater.js +0 -103
- package/dist/lib/mathquill/package-updater.js.map +0 -1
- package/dist/lib/mathquill/pie-extractor.d.ts +0 -14
- package/dist/lib/mathquill/pie-extractor.d.ts.map +0 -1
- package/dist/lib/mathquill/pie-extractor.js +0 -167
- package/dist/lib/mathquill/pie-extractor.js.map +0 -1
- package/dist/lib/upstream/repo-utils.d.ts.map +0 -1
- package/dist/lib/upstream/sync-compatibility.d.ts.map +0 -1
- package/dist/lib/upstream/sync-constants.d.ts.map +0 -1
- package/dist/lib/upstream/sync-controllers-strategy.d.ts.map +0 -1
- package/dist/lib/upstream/sync-demo-metadata.d.ts.map +0 -1
- package/dist/lib/upstream/sync-dev-exports.d.ts +0 -13
- package/dist/lib/upstream/sync-dev-exports.d.ts.map +0 -1
- package/dist/lib/upstream/sync-dev-exports.js +0 -115
- package/dist/lib/upstream/sync-dev-exports.js.map +0 -1
- package/dist/lib/upstream/sync-externals.d.ts.map +0 -1
- package/dist/lib/upstream/sync-filesystem.d.ts.map +0 -1
- package/dist/lib/upstream/sync-imports.d.ts.map +0 -1
- package/dist/lib/upstream/sync-mathquill.d.ts +0 -19
- package/dist/lib/upstream/sync-mathquill.d.ts.map +0 -1
- package/dist/lib/upstream/sync-mathquill.js +0 -160
- package/dist/lib/upstream/sync-mathquill.js.map +0 -1
- package/dist/lib/upstream/sync-package-json.d.ts.map +0 -1
- package/dist/lib/upstream/sync-package-manager.d.ts.map +0 -1
- package/dist/lib/upstream/sync-pielib-strategy.d.ts.map +0 -1
- package/dist/lib/upstream/sync-react-strategy.d.ts.map +0 -1
- package/dist/lib/upstream/sync-strategy.d.ts.map +0 -1
- package/dist/lib/upstream/sync-summary.d.ts.map +0 -1
- package/dist/lib/upstream/sync-transforms.d.ts.map +0 -1
- package/dist/lib/upstream/sync-vite-config.d.ts.map +0 -1
- package/dist/utils/compatibility.d.ts.map +0 -1
- package/dist/utils/conversion.d.ts.map +0 -1
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/package-json.d.ts.map +0 -1
- package/packages/cli/bin/dev.js +0 -5
- package/packages/cli/bin/run.js +0 -5
- package/src/commands/dev/demo/index.ts +0 -313
- package/src/commands/dev/test-bundler.ts +0 -345
- package/src/commands/mathquill/migrate.ts +0 -269
- package/src/commands/mathquill/status.ts +0 -267
- package/src/commands/packages/create-controllers.ts +0 -127
- package/src/commands/packages/create-lib-react.ts +0 -279
- package/src/commands/packages/create-react-elements.ts +0 -306
- package/src/commands/packages/enable-publishing.ts +0 -161
- package/src/commands/packages/init-synced-elements.ts +0 -259
- package/src/commands/upstream/README.md +0 -444
- package/src/commands/upstream/analyze-esm.ts +0 -1973
- package/src/commands/upstream/check.ts +0 -228
- package/src/commands/upstream/deps.ts +0 -222
- package/src/commands/upstream/sync-mathquill.ts +0 -108
- package/src/commands/upstream/sync.ts +0 -687
- package/src/commands/upstream/track.ts +0 -145
- package/src/commands/upstream/update.ts +0 -110
- package/src/commands/verify/controllers.ts +0 -166
- package/src/commands/verify/react-build.ts +0 -171
- package/src/index.ts +0 -1
- package/src/lib/mathquill/extension-generator.ts +0 -111
- package/src/lib/mathquill/khan-extractor.ts +0 -175
- package/src/lib/mathquill/learnosity-extractor.ts +0 -198
- package/src/lib/mathquill/migration-orchestrator.ts +0 -513
- package/src/lib/mathquill/package-updater.ts +0 -120
- package/src/lib/mathquill/pie-extractor.ts +0 -194
- package/src/lib/upstream/repo-utils.ts +0 -18
- package/src/lib/upstream/sync-compatibility.ts +0 -89
- package/src/lib/upstream/sync-constants.ts +0 -77
- package/src/lib/upstream/sync-controllers-strategy.ts +0 -291
- package/src/lib/upstream/sync-demo-metadata.ts +0 -199
- package/src/lib/upstream/sync-dev-exports.ts +0 -151
- package/src/lib/upstream/sync-externals.ts +0 -159
- package/src/lib/upstream/sync-filesystem.ts +0 -87
- package/src/lib/upstream/sync-imports.ts +0 -992
- package/src/lib/upstream/sync-mathquill.ts +0 -194
- package/src/lib/upstream/sync-package-json.ts +0 -86
- package/src/lib/upstream/sync-package-manager.ts +0 -694
- package/src/lib/upstream/sync-pielib-strategy.ts +0 -441
- package/src/lib/upstream/sync-react-strategy.ts +0 -945
- package/src/lib/upstream/sync-strategy.ts +0 -61
- package/src/lib/upstream/sync-summary.ts +0 -194
- package/src/lib/upstream/sync-transforms.ts +0 -154
- package/src/lib/upstream/sync-vite-config.ts +0 -243
- package/src/types/es-module-lexer.d.ts +0 -4
- package/src/utils/compatibility.ts +0 -182
- package/src/utils/conversion.ts +0 -153
- package/src/utils/git.ts +0 -63
- package/src/utils/logger.ts +0 -69
- package/src/utils/package-json.ts +0 -43
- package/tests/sync-package-manager.test.ts +0 -112
- package/tests/transform-assign-props.test.ts +0 -101
- package/tsconfig.json +0 -15
|
@@ -5,32 +5,33 @@
|
|
|
5
5
|
* composable pipeline to reduce duplication and ensure consistent transformations
|
|
6
6
|
* across all sync strategies.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { transformLodashToVendoredLodash, transformKnownDeepImportsToFullySpecified, transformPieFrameworkEventImports, transformControllerUtilsImports, transformSharedPackageImports, transformLegacyConfigureLibImports, inlineEditableHtmlConstants, reexportTokenTypes, transformSsrRequireToEsmImport, inlineConfigureDefaults, transformConfigureUtilsImports, transformSelfReferentialImports, transformPackageJsonLodash, transformPackageJsonRecharts, transformPackageJsonPieEvents, transformPackageJsonControllerUtils, transformPackageJsonSharedPackages, fixStyledComponentTypes, fixExportedFunctionTypes, transformMenuToInlineMenu, addInlineMenuExport, transformReactInteropComponentImports, transformClassnamesToClsx, transformConfigUiMathjsToLocalFraction, transformReactInputAutosizeToLocal, transformPackageJsonBrowserEsmDependencies, } from './sync-imports.js';
|
|
9
9
|
/**
|
|
10
10
|
* Apply all standard source code transformations in the correct order
|
|
11
11
|
*
|
|
12
12
|
* This ensures consistent transformation across all sync strategies:
|
|
13
|
-
* 1. lodash → lodash
|
|
13
|
+
* 1. lodash/lodash-es → @pie-element/shared-lodash (vendored ESM helpers)
|
|
14
14
|
* 2. @pie-framework event packages → internal packages
|
|
15
15
|
* 3. @pie-lib/controller-utils → @pie-framework/controller-utils
|
|
16
16
|
* 4. @pie-lib shared packages → @pie-element/shared-*
|
|
17
|
-
* 5. @
|
|
18
|
-
* 6.
|
|
19
|
-
* 7.
|
|
20
|
-
* 8.
|
|
21
|
-
* 9.
|
|
22
|
-
* 10. Fix styled component TypeScript type inference errors
|
|
17
|
+
* 5. @mui/material/Menu → InlineMenu from @pie-lib/render-ui
|
|
18
|
+
* 6. Self-referential imports → relative imports
|
|
19
|
+
* 7. Configure-specific transforms (if enabled)
|
|
20
|
+
* 8. Pie-lib-specific transforms (if enabled)
|
|
21
|
+
* 9. Fix styled component TypeScript type inference errors
|
|
23
22
|
*/
|
|
24
23
|
export function applySourceTransforms(content, options = {}) {
|
|
25
24
|
let transformed = content;
|
|
26
25
|
// Core transforms (always applied)
|
|
27
|
-
transformed =
|
|
26
|
+
transformed = transformLodashToVendoredLodash(transformed);
|
|
27
|
+
transformed = transformClassnamesToClsx(transformed);
|
|
28
|
+
transformed = transformKnownDeepImportsToFullySpecified(transformed);
|
|
28
29
|
transformed = transformPieFrameworkEventImports(transformed);
|
|
29
30
|
transformed = transformControllerUtilsImports(transformed);
|
|
30
31
|
transformed = transformSharedPackageImports(transformed);
|
|
31
|
-
transformed =
|
|
32
|
-
transformed = transformMathQuillInterface(transformed);
|
|
32
|
+
transformed = transformLegacyConfigureLibImports(transformed);
|
|
33
33
|
transformed = transformMenuToInlineMenu(transformed);
|
|
34
|
+
transformed = transformReactInteropComponentImports(transformed);
|
|
34
35
|
// Transform self-referential imports to relative paths
|
|
35
36
|
if (options.packageName && options.relativePath) {
|
|
36
37
|
transformed = transformSelfReferentialImports(transformed, options.packageName, options.relativePath);
|
|
@@ -42,14 +43,16 @@ export function applySourceTransforms(content, options = {}) {
|
|
|
42
43
|
transformed = transformConfigureUtilsImports(transformed, options.relativePath);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
// Pie-lib-specific transforms
|
|
46
|
+
// Pie-lib-specific transforms (run only when syncing upstream pie-lib sources)
|
|
46
47
|
if (options.includePieLib) {
|
|
48
|
+
transformed = transformReactInputAutosizeToLocal(transformed, options.sourcePath);
|
|
49
|
+
transformed = transformConfigUiMathjsToLocalFraction(transformed, options.sourcePath);
|
|
47
50
|
transformed = inlineEditableHtmlConstants(transformed);
|
|
48
51
|
if (options.sourcePath) {
|
|
49
52
|
transformed = reexportTokenTypes(transformed, options.sourcePath);
|
|
50
53
|
transformed = addInlineMenuExport(transformed, options.sourcePath);
|
|
51
54
|
}
|
|
52
|
-
transformed =
|
|
55
|
+
transformed = transformSsrRequireToEsmImport(transformed);
|
|
53
56
|
}
|
|
54
57
|
// TypeScript fixes (always applied)
|
|
55
58
|
transformed = fixStyledComponentTypes(transformed);
|
|
@@ -60,20 +63,23 @@ export function applySourceTransforms(content, options = {}) {
|
|
|
60
63
|
* Apply all standard package.json transformations
|
|
61
64
|
*
|
|
62
65
|
* Ensures consistent dependency transformations across all packages:
|
|
63
|
-
* 1. lodash → lodash
|
|
66
|
+
* 1. lodash/lodash-es → @pie-element/shared-lodash
|
|
64
67
|
* 2. @pie-framework event packages → internal packages
|
|
65
68
|
* 3. @pie-lib/controller-utils → @pie-framework/controller-utils
|
|
66
69
|
* 4. @pie-lib shared packages → @pie-element/shared-*
|
|
67
|
-
* 5. @pie-framework/mathquill
|
|
70
|
+
* 5. Preserve upstream @pie-framework/mathquill dependency versions from synced package.json
|
|
68
71
|
*/
|
|
69
|
-
export function applyPackageJsonTransforms(pkg) {
|
|
72
|
+
export function applyPackageJsonTransforms(pkg, options = {}) {
|
|
70
73
|
let transformed = pkg;
|
|
71
74
|
transformed = transformPackageJsonLodash(transformed);
|
|
72
75
|
transformed = transformPackageJsonRecharts(transformed);
|
|
76
|
+
transformed = transformPackageJsonBrowserEsmDependencies(transformed, {
|
|
77
|
+
removeReactInputAutosize: options.removeReactInputAutosize,
|
|
78
|
+
removeMathjs: options.removeMathjs,
|
|
79
|
+
});
|
|
73
80
|
transformed = transformPackageJsonPieEvents(transformed);
|
|
74
81
|
transformed = transformPackageJsonControllerUtils(transformed);
|
|
75
82
|
transformed = transformPackageJsonSharedPackages(transformed);
|
|
76
|
-
transformed = transformPackageJsonMathquill(transformed);
|
|
77
83
|
return transformed;
|
|
78
84
|
}
|
|
79
85
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-transforms.js","sourceRoot":"","sources":["../../../src/lib/upstream/sync-transforms.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"sync-transforms.js","sourceRoot":"","sources":["../../../src/lib/upstream/sync-transforms.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,+BAA+B,EAC/B,yCAAyC,EACzC,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,kCAAkC,EAClC,2BAA2B,EAC3B,kBAAkB,EAClB,8BAA8B,EAC9B,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC5B,6BAA6B,EAC7B,mCAAmC,EACnC,kCAAkC,EAClC,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,qCAAqC,EACrC,yBAAyB,EACzB,sCAAsC,EACtC,kCAAkC,EAClC,0CAA0C,GAC3C,MAAM,mBAAmB,CAAC;AAoB3B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe,EAAE,UAA4B,EAAE;IACnF,IAAI,WAAW,GAAG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E,YAAqB,EAAE,EAAE,CAChD,qBAAqB,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,CAAC,OAAe,EAAE,UAAmB,EAAE,EAAE,CAC9C,qBAAqB,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/**\n * Centralized transformation pipeline for upstream sync operations\n *\n * This module consolidates all source code transformations into a single,\n * composable pipeline to reduce duplication and ensure consistent transformations\n * across all sync strategies.\n */\n\nimport {\n transformLodashToVendoredLodash,\n transformKnownDeepImportsToFullySpecified,\n transformPieFrameworkEventImports,\n transformControllerUtilsImports,\n transformSharedPackageImports,\n transformLegacyConfigureLibImports,\n inlineEditableHtmlConstants,\n reexportTokenTypes,\n transformSsrRequireToEsmImport,\n inlineConfigureDefaults,\n transformConfigureUtilsImports,\n transformSelfReferentialImports,\n transformPackageJsonLodash,\n transformPackageJsonRecharts,\n transformPackageJsonPieEvents,\n transformPackageJsonControllerUtils,\n transformPackageJsonSharedPackages,\n fixStyledComponentTypes,\n fixExportedFunctionTypes,\n transformMenuToInlineMenu,\n addInlineMenuExport,\n transformReactInteropComponentImports,\n transformClassnamesToClsx,\n transformConfigUiMathjsToLocalFraction,\n transformReactInputAutosizeToLocal,\n transformPackageJsonBrowserEsmDependencies,\n} from './sync-imports.js';\nimport type { PackageJson } from '../../utils/package-json.js';\n\nexport interface TransformOptions {\n /** Path relative to package root (e.g., \"configure/src/utils.js\") */\n relativePath?: string;\n /** Source file path for context (e.g., \"/path/to/file.js\") */\n sourcePath?: string;\n /** Package name (e.g., \"@pie-element/fraction-model\") */\n packageName?: string;\n /** Whether to include configure-specific transforms */\n includeConfigure?: boolean;\n /** Whether to include pie-lib-specific transforms */\n includePieLib?: boolean;\n /** Whether to remove react-input-autosize from package metadata */\n removeReactInputAutosize?: boolean;\n /** Whether to remove mathjs from package metadata */\n removeMathjs?: boolean;\n}\n\n/**\n * Apply all standard source code transformations in the correct order\n *\n * This ensures consistent transformation across all sync strategies:\n * 1. lodash/lodash-es → @pie-element/shared-lodash (vendored ESM helpers)\n * 2. @pie-framework event packages → internal packages\n * 3. @pie-lib/controller-utils → @pie-framework/controller-utils\n * 4. @pie-lib shared packages → @pie-element/shared-*\n * 5. @mui/material/Menu → InlineMenu from @pie-lib/render-ui\n * 6. Self-referential imports → relative imports\n * 7. Configure-specific transforms (if enabled)\n * 8. Pie-lib-specific transforms (if enabled)\n * 9. Fix styled component TypeScript type inference errors\n */\nexport function applySourceTransforms(content: string, options: TransformOptions = {}): string {\n let transformed = content;\n\n // Core transforms (always applied)\n transformed = transformLodashToVendoredLodash(transformed);\n transformed = transformClassnamesToClsx(transformed);\n transformed = transformKnownDeepImportsToFullySpecified(transformed);\n transformed = transformPieFrameworkEventImports(transformed);\n transformed = transformControllerUtilsImports(transformed);\n transformed = transformSharedPackageImports(transformed);\n transformed = transformLegacyConfigureLibImports(transformed);\n transformed = transformMenuToInlineMenu(transformed);\n transformed = transformReactInteropComponentImports(transformed);\n\n // Transform self-referential imports to relative paths\n if (options.packageName && options.relativePath) {\n transformed = transformSelfReferentialImports(\n transformed,\n options.packageName,\n options.relativePath\n );\n }\n\n // Configure-specific transforms\n if (options.includeConfigure) {\n transformed = inlineConfigureDefaults(transformed);\n if (options.relativePath) {\n transformed = transformConfigureUtilsImports(transformed, options.relativePath);\n }\n }\n\n // Pie-lib-specific transforms (run only when syncing upstream pie-lib sources)\n if (options.includePieLib) {\n transformed = transformReactInputAutosizeToLocal(transformed, options.sourcePath);\n transformed = transformConfigUiMathjsToLocalFraction(transformed, options.sourcePath);\n transformed = inlineEditableHtmlConstants(transformed);\n if (options.sourcePath) {\n transformed = reexportTokenTypes(transformed, options.sourcePath);\n transformed = addInlineMenuExport(transformed, options.sourcePath);\n }\n transformed = transformSsrRequireToEsmImport(transformed);\n }\n\n // TypeScript fixes (always applied)\n transformed = fixStyledComponentTypes(transformed);\n transformed = fixExportedFunctionTypes(transformed, options.sourcePath);\n\n return transformed;\n}\n\n/**\n * Apply all standard package.json transformations\n *\n * Ensures consistent dependency transformations across all packages:\n * 1. lodash/lodash-es → @pie-element/shared-lodash\n * 2. @pie-framework event packages → internal packages\n * 3. @pie-lib/controller-utils → @pie-framework/controller-utils\n * 4. @pie-lib shared packages → @pie-element/shared-*\n * 5. Preserve upstream @pie-framework/mathquill dependency versions from synced package.json\n */\nexport function applyPackageJsonTransforms<T extends PackageJson>(\n pkg: T,\n options: TransformOptions = {}\n): T {\n let transformed = pkg;\n\n transformed = transformPackageJsonLodash(transformed);\n transformed = transformPackageJsonRecharts(transformed);\n transformed = transformPackageJsonBrowserEsmDependencies(transformed, {\n removeReactInputAutosize: options.removeReactInputAutosize,\n removeMathjs: options.removeMathjs,\n });\n transformed = transformPackageJsonPieEvents(transformed);\n transformed = transformPackageJsonControllerUtils(transformed);\n transformed = transformPackageJsonSharedPackages(transformed);\n\n return transformed;\n}\n\n/**\n * Create a transform pipeline for controller files\n */\nexport function createControllerTransformPipeline(packageName?: string) {\n return (content: string, relativePath?: string) =>\n applySourceTransforms(content, { relativePath, packageName, includeConfigure: false });\n}\n\n/**\n * Create a transform pipeline for React component files\n */\nexport function createReactComponentTransformPipeline(packageName?: string) {\n return (content: string, relativePath?: string) =>\n applySourceTransforms(content, { relativePath, packageName, includeConfigure: true });\n}\n\n/**\n * Create a transform pipeline for pie-lib files\n */\nexport function createPieLibTransformPipeline() {\n return (content: string, sourcePath?: string) =>\n applySourceTransforms(content, { sourcePath, includePieLib: true });\n}\n"]}
|
|
@@ -4,10 +4,22 @@
|
|
|
4
4
|
export declare function detectElementEntryPoints(elementDir: string): Record<string, string>;
|
|
5
5
|
/**
|
|
6
6
|
* Generate Vite config content for an element package
|
|
7
|
+
*
|
|
8
|
+
* @tech-debt The __PIE_PACKAGE_VERSION__ injection was added in commit 8a579dfe
|
|
9
|
+
* "fix: support private child elements in browser esm" to enable version-scoped
|
|
10
|
+
* custom element registration (e.g., 'ebsr-multiple-choice--version-8-1-1').
|
|
11
|
+
*
|
|
12
|
+
* This prevents name collisions when multiple versions of elements coexist in
|
|
13
|
+
* browser ESM bundles. However, it adds boilerplate to all 51+ element configs,
|
|
14
|
+
* even though only ~2 elements (EBSR, complex-rubric) actually need it.
|
|
15
|
+
*
|
|
16
|
+
* Consider refactoring:
|
|
17
|
+
* - Move to shared @pie-element/vite-plugin-version
|
|
18
|
+
* - Only inject for elements with private children
|
|
19
|
+
* - Use runtime version detection instead of compile-time injection
|
|
7
20
|
*/
|
|
8
21
|
export declare function generateElementViteConfig(entryPoints: Record<string, string>): string;
|
|
9
22
|
/**
|
|
10
23
|
* Generate Vite config content for a pie-lib package
|
|
11
24
|
*/
|
|
12
25
|
export declare function generatePieLibViteConfig(packageName?: string, packageDir?: string): string;
|
|
13
|
-
//# sourceMappingURL=sync-vite-config.d.ts.map
|
|
@@ -1,58 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vite configuration generation for sync operations
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { join } from 'node:path';
|
|
4
|
+
import { collectEntryPoints, detectEntryFile } from './sync-entry-discovery.js';
|
|
6
5
|
import { createExternalFunction } from './sync-externals.js';
|
|
7
|
-
|
|
8
|
-
* Detect the actual file extension for a source file
|
|
9
|
-
*/
|
|
10
|
-
function detectFileExtension(basePath) {
|
|
11
|
-
if (existsSync(`${basePath}.tsx`))
|
|
12
|
-
return '.tsx';
|
|
13
|
-
if (existsSync(`${basePath}.ts`))
|
|
14
|
-
return '.ts';
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
6
|
+
import { getPieLibVitePreset } from './sync-presets.js';
|
|
17
7
|
/**
|
|
18
8
|
* Detect entry points for an element package
|
|
19
9
|
*/
|
|
20
10
|
export function detectElementEntryPoints(elementDir) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Controller
|
|
28
|
-
const controllerExt = detectFileExtension(join(elementDir, 'src/controller/index'));
|
|
29
|
-
if (controllerExt) {
|
|
30
|
-
entryPoints['controller/index'] = `src/controller/index${controllerExt}`;
|
|
31
|
-
}
|
|
32
|
-
// Configure
|
|
33
|
-
const configureExt = detectFileExtension(join(elementDir, 'src/configure/index'));
|
|
34
|
-
if (configureExt) {
|
|
35
|
-
entryPoints['configure/index'] = `src/configure/index${configureExt}`;
|
|
36
|
-
}
|
|
37
|
-
// Delivery
|
|
38
|
-
const deliveryExt = detectFileExtension(join(elementDir, 'src/delivery/index'));
|
|
39
|
-
if (deliveryExt) {
|
|
40
|
-
entryPoints['delivery/index'] = `src/delivery/index${deliveryExt}`;
|
|
41
|
-
}
|
|
42
|
-
return entryPoints;
|
|
11
|
+
return collectEntryPoints(elementDir, [
|
|
12
|
+
['index', 'src/index'],
|
|
13
|
+
['controller/index', 'src/controller/index'],
|
|
14
|
+
['configure/index', 'src/configure/index'],
|
|
15
|
+
['delivery/index', 'src/delivery/index'],
|
|
16
|
+
]);
|
|
43
17
|
}
|
|
44
18
|
/**
|
|
45
19
|
* Generate Vite config content for an element package
|
|
20
|
+
*
|
|
21
|
+
* @tech-debt The __PIE_PACKAGE_VERSION__ injection was added in commit 8a579dfe
|
|
22
|
+
* "fix: support private child elements in browser esm" to enable version-scoped
|
|
23
|
+
* custom element registration (e.g., 'ebsr-multiple-choice--version-8-1-1').
|
|
24
|
+
*
|
|
25
|
+
* This prevents name collisions when multiple versions of elements coexist in
|
|
26
|
+
* browser ESM bundles. However, it adds boilerplate to all 51+ element configs,
|
|
27
|
+
* even though only ~2 elements (EBSR, complex-rubric) actually need it.
|
|
28
|
+
*
|
|
29
|
+
* Consider refactoring:
|
|
30
|
+
* - Move to shared @pie-element/vite-plugin-version
|
|
31
|
+
* - Only inject for elements with private children
|
|
32
|
+
* - Use runtime version detection instead of compile-time injection
|
|
46
33
|
*/
|
|
47
34
|
export function generateElementViteConfig(entryPoints) {
|
|
48
35
|
if (Object.keys(entryPoints).length === 0) {
|
|
49
36
|
throw new Error('No entry points found for element');
|
|
50
37
|
}
|
|
51
38
|
const entryJson = JSON.stringify(entryPoints, null, 8).replace(/^/gm, ' ');
|
|
52
|
-
return `import {
|
|
39
|
+
return `import { readFileSync } from 'node:fs';
|
|
40
|
+
import { resolve } from 'node:path';
|
|
53
41
|
import react from '@vitejs/plugin-react';
|
|
54
42
|
import { defineConfig } from 'vite';
|
|
55
43
|
|
|
44
|
+
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8')) as {
|
|
45
|
+
name?: string;
|
|
46
|
+
version?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
56
49
|
export default defineConfig(({ mode }) => {
|
|
57
50
|
// Demo mode: serve the docs/demo directory
|
|
58
51
|
if (mode === 'demo') {
|
|
@@ -68,6 +61,10 @@ export default defineConfig(({ mode }) => {
|
|
|
68
61
|
// Build mode: build the library
|
|
69
62
|
return {
|
|
70
63
|
plugins: [react()],
|
|
64
|
+
define: {
|
|
65
|
+
__PIE_PACKAGE_NAME__: JSON.stringify(packageJson.name ?? ''),
|
|
66
|
+
__PIE_PACKAGE_VERSION__: JSON.stringify(packageJson.version ?? 'local'),
|
|
67
|
+
},
|
|
71
68
|
build: {
|
|
72
69
|
lib: {
|
|
73
70
|
entry: ${entryJson.trimStart()},
|
|
@@ -92,17 +89,21 @@ export function generatePieLibViteConfig(packageName, packageDir) {
|
|
|
92
89
|
// Detect entry point extension if package directory provided
|
|
93
90
|
let entryPoint = 'src/index.ts';
|
|
94
91
|
if (packageDir) {
|
|
95
|
-
|
|
96
|
-
if (ext) {
|
|
97
|
-
entryPoint = `src/index${ext}`;
|
|
98
|
-
}
|
|
92
|
+
entryPoint = detectEntryFile(packageDir, 'src/index') ?? entryPoint;
|
|
99
93
|
}
|
|
94
|
+
const preset = getPieLibVitePreset(packageName);
|
|
100
95
|
// Special config for math-rendering wrapper (externalizes adapter package)
|
|
101
|
-
if (
|
|
96
|
+
if (preset === 'math-rendering-wrapper') {
|
|
102
97
|
return `import { resolve } from 'node:path';
|
|
103
98
|
import { defineConfig } from 'vite';
|
|
104
99
|
|
|
105
100
|
export default defineConfig({
|
|
101
|
+
// ESM-first resolution. A dependency with no exports map (@visx/* v3,
|
|
102
|
+
// @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and
|
|
103
|
+
// bundling CommonJS while React is external makes rolldown emit a
|
|
104
|
+
// require("react") shim that throws in the browser. Preferring the module
|
|
105
|
+
// field resolves those dependencies to their ESM build instead.
|
|
106
|
+
resolve: { mainFields: ['module', 'browser', 'main'] },
|
|
106
107
|
build: {
|
|
107
108
|
lib: {
|
|
108
109
|
entry: {
|
|
@@ -129,12 +130,18 @@ export default defineConfig({
|
|
|
129
130
|
`;
|
|
130
131
|
}
|
|
131
132
|
// Special config for test-utils (includes testing library externals)
|
|
132
|
-
if (
|
|
133
|
+
if (preset === 'test-utils') {
|
|
133
134
|
return `import { resolve } from 'node:path';
|
|
134
135
|
import react from '@vitejs/plugin-react';
|
|
135
136
|
import { defineConfig } from 'vite';
|
|
136
137
|
|
|
137
138
|
export default defineConfig({
|
|
139
|
+
// ESM-first resolution. A dependency with no exports map (@visx/* v3,
|
|
140
|
+
// @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and
|
|
141
|
+
// bundling CommonJS while React is external makes rolldown emit a
|
|
142
|
+
// require("react") shim that throws in the browser. Preferring the module
|
|
143
|
+
// field resolves those dependencies to their ESM build instead.
|
|
144
|
+
resolve: { mainFields: ['module', 'browser', 'main'] },
|
|
138
145
|
plugins: [react()],
|
|
139
146
|
build: {
|
|
140
147
|
lib: {
|
|
@@ -155,12 +162,18 @@ export default defineConfig({
|
|
|
155
162
|
`;
|
|
156
163
|
}
|
|
157
164
|
// Special config for editable-html-tip-tap (externalizes prosemirror and tiptap)
|
|
158
|
-
if (
|
|
165
|
+
if (preset === 'editable-html-tip-tap') {
|
|
159
166
|
return `import { resolve } from 'node:path';
|
|
160
167
|
import react from '@vitejs/plugin-react';
|
|
161
168
|
import { defineConfig } from 'vite';
|
|
162
169
|
|
|
163
170
|
export default defineConfig({
|
|
171
|
+
// ESM-first resolution. A dependency with no exports map (@visx/* v3,
|
|
172
|
+
// @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and
|
|
173
|
+
// bundling CommonJS while React is external makes rolldown emit a
|
|
174
|
+
// require("react") shim that throws in the browser. Preferring the module
|
|
175
|
+
// field resolves those dependencies to their ESM build instead.
|
|
176
|
+
resolve: { mainFields: ['module', 'browser', 'main'] },
|
|
164
177
|
plugins: [react()],
|
|
165
178
|
build: {
|
|
166
179
|
lib: {
|
|
@@ -182,8 +195,6 @@ export default defineConfig({
|
|
|
182
195
|
/^@emotion\\//.test(id) ||
|
|
183
196
|
/^d3-/.test(id) ||
|
|
184
197
|
/^@testing-library\\//.test(id) ||
|
|
185
|
-
id === 'lodash-es' ||
|
|
186
|
-
/^lodash-es\\//.test(id) ||
|
|
187
198
|
/^styled-components/.test(id) ||
|
|
188
199
|
id === 'konva' || /^konva\\//.test(id) ||
|
|
189
200
|
id === 'react-konva' || /^react-konva\\//.test(id) ||
|
|
@@ -191,7 +202,7 @@ export default defineConfig({
|
|
|
191
202
|
id === '@mdi/js' || /^@mdi\\/js\\//.test(id) ||
|
|
192
203
|
/^prosemirror-/.test(id) ||
|
|
193
204
|
/^@tiptap\\//.test(id) ||
|
|
194
|
-
['prop-types', '
|
|
205
|
+
['prop-types', 'debug', 'i18next', 'humps', 'mathjs', 'react-jss', 'js-combinatorics', '@dnd-kit/core', 'react-transition-group'].includes(id)
|
|
195
206
|
);
|
|
196
207
|
},
|
|
197
208
|
output: {
|
|
@@ -209,6 +220,12 @@ import react from '@vitejs/plugin-react';
|
|
|
209
220
|
import { defineConfig } from 'vite';
|
|
210
221
|
|
|
211
222
|
export default defineConfig({
|
|
223
|
+
// ESM-first resolution. A dependency with no exports map (@visx/* v3,
|
|
224
|
+
// @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and
|
|
225
|
+
// bundling CommonJS while React is external makes rolldown emit a
|
|
226
|
+
// require("react") shim that throws in the browser. Preferring the module
|
|
227
|
+
// field resolves those dependencies to their ESM build instead.
|
|
228
|
+
resolve: { mainFields: ['module', 'browser', 'main'] },
|
|
212
229
|
plugins: [react()],
|
|
213
230
|
build: {
|
|
214
231
|
lib: {
|
|
@@ -218,7 +235,9 @@ export default defineConfig({
|
|
|
218
235
|
formats: ['es'],
|
|
219
236
|
},
|
|
220
237
|
rollupOptions: {
|
|
221
|
-
external: ${createExternalFunction('pielib'
|
|
238
|
+
external: ${createExternalFunction('pielib', {
|
|
239
|
+
externalizeMathjs: packageName !== 'config-ui',
|
|
240
|
+
})},
|
|
222
241
|
output: {
|
|
223
242
|
preserveModules: true,
|
|
224
243
|
preserveModulesRoot: 'src',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-vite-config.js","sourceRoot":"","sources":["../../../src/lib/upstream/sync-vite-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,IAAI,UAAU,CAAC,GAAG,QAAQ,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACjD,IAAI,UAAU,CAAC,GAAG,QAAQ,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACzD,MAAM,WAAW,GAA2B,EAAE,CAAC;IAE/C,aAAa;IACb,MAAM,QAAQ,GA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IACA,CAAC;IAED,qEAAqE;IACrE,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;QAC5B,OAAO;;;;;;;;;;;;;;;qCAe0B,UAAU;;;;;kBAK7B,sBAAsB,CAAC,QAAQ,CAAC;;;;;;;;CAQjD,CAAC;IACA,CAAC;IAED,iFAAiF;IACjF,IAAI,MAAM,KAAK,uBAAuB,EAAE,CAAC;QACvC,OAAO;;;;;;;;;;;;;;;qCAe0B,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC9C,CAAC;IACA,CAAC;IAED,yBAAyB;IACzB,OAAO;;;;;;;;;;;;;;;qCAe4B,UAAU;;;;;kBAK7B,sBAAsB,CAAC,QAAQ,EAAE;QAC3C,iBAAiB,EAAE,WAAW,KAAK,WAAW;KAC/C,CAAC;;;;;;;;CAQP,CAAC;AACF,CAAC","sourcesContent":["/**\n * Vite configuration generation for sync operations\n */\nimport { collectEntryPoints, detectEntryFile } from './sync-entry-discovery.js';\nimport { createExternalFunction } from './sync-externals.js';\nimport { getPieLibVitePreset } from './sync-presets.js';\n\n/**\n * Detect entry points for an element package\n */\nexport function detectElementEntryPoints(elementDir: string): Record<string, string> {\n return collectEntryPoints(elementDir, [\n ['index', 'src/index'],\n ['controller/index', 'src/controller/index'],\n ['configure/index', 'src/configure/index'],\n ['delivery/index', 'src/delivery/index'],\n ]);\n}\n\n/**\n * Generate Vite config content for an element package\n *\n * @tech-debt The __PIE_PACKAGE_VERSION__ injection was added in commit 8a579dfe\n * \"fix: support private child elements in browser esm\" to enable version-scoped\n * custom element registration (e.g., 'ebsr-multiple-choice--version-8-1-1').\n *\n * This prevents name collisions when multiple versions of elements coexist in\n * browser ESM bundles. However, it adds boilerplate to all 51+ element configs,\n * even though only ~2 elements (EBSR, complex-rubric) actually need it.\n *\n * Consider refactoring:\n * - Move to shared @pie-element/vite-plugin-version\n * - Only inject for elements with private children\n * - Use runtime version detection instead of compile-time injection\n */\nexport function generateElementViteConfig(entryPoints: Record<string, string>): string {\n if (Object.keys(entryPoints).length === 0) {\n throw new Error('No entry points found for element');\n }\n\n const entryJson = JSON.stringify(entryPoints, null, 8).replace(/^/gm, ' ');\n\n return `import { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport { defineConfig } from 'vite';\n\nconst packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8')) as {\n name?: string;\n version?: string;\n};\n\nexport default defineConfig(({ mode }) => {\n // Demo mode: serve the docs/demo directory\n if (mode === 'demo') {\n return {\n plugins: [react()],\n root: 'docs/demo',\n server: {\n port: 5174,\n },\n };\n }\n\n // Build mode: build the library\n return {\n plugins: [react()],\n define: {\n __PIE_PACKAGE_NAME__: JSON.stringify(packageJson.name ?? ''),\n __PIE_PACKAGE_VERSION__: JSON.stringify(packageJson.version ?? 'local'),\n },\n build: {\n lib: {\n entry: ${entryJson.trimStart()},\n formats: ['es'],\n },\n rollupOptions: {\n external: ${createExternalFunction('element')},\n output: {\n preserveModules: true,\n preserveModulesRoot: 'src',\n },\n },\n },\n };\n});\n`;\n}\n\n/**\n * Generate Vite config content for a pie-lib package\n */\nexport function generatePieLibViteConfig(packageName?: string, packageDir?: string): string {\n // Detect entry point extension if package directory provided\n let entryPoint = 'src/index.ts';\n if (packageDir) {\n entryPoint = detectEntryFile(packageDir, 'src/index') ?? entryPoint;\n }\n\n const preset = getPieLibVitePreset(packageName);\n\n // Special config for math-rendering wrapper (externalizes adapter package)\n if (preset === 'math-rendering-wrapper') {\n return `import { resolve } from 'node:path';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n // ESM-first resolution. A dependency with no exports map (@visx/* v3,\n // @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and\n // bundling CommonJS while React is external makes rolldown emit a\n // require(\"react\") shim that throws in the browser. Preferring the module\n // field resolves those dependencies to their ESM build instead.\n resolve: { mainFields: ['module', 'browser', 'main'] },\n build: {\n lib: {\n entry: {\n index: resolve(__dirname, '${entryPoint}'),\n },\n formats: ['es'],\n },\n rollupOptions: {\n external: (id) => {\n return (\n /^@pie-element\\\\/shared-/.test(id) ||\n id === '@pie-element/shared-math-rendering-mathjax' ||\n /^@pie-lib\\\\//.test(id) ||\n ['debug'].includes(id)\n );\n },\n output: {\n preserveModules: true,\n preserveModulesRoot: 'src',\n },\n },\n },\n});\n`;\n }\n\n // Special config for test-utils (includes testing library externals)\n if (preset === 'test-utils') {\n return `import { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n // ESM-first resolution. A dependency with no exports map (@visx/* v3,\n // @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and\n // bundling CommonJS while React is external makes rolldown emit a\n // require(\"react\") shim that throws in the browser. Preferring the module\n // field resolves those dependencies to their ESM build instead.\n resolve: { mainFields: ['module', 'browser', 'main'] },\n plugins: [react()],\n build: {\n lib: {\n entry: {\n index: resolve(__dirname, '${entryPoint}'),\n },\n formats: ['es'],\n },\n rollupOptions: {\n external: ${createExternalFunction('pielib')},\n output: {\n preserveModules: true,\n preserveModulesRoot: 'src',\n },\n },\n },\n});\n`;\n }\n\n // Special config for editable-html-tip-tap (externalizes prosemirror and tiptap)\n if (preset === 'editable-html-tip-tap') {\n return `import { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n // ESM-first resolution. A dependency with no exports map (@visx/* v3,\n // @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and\n // bundling CommonJS while React is external makes rolldown emit a\n // require(\"react\") shim that throws in the browser. Preferring the module\n // field resolves those dependencies to their ESM build instead.\n resolve: { mainFields: ['module', 'browser', 'main'] },\n plugins: [react()],\n build: {\n lib: {\n entry: {\n index: resolve(__dirname, '${entryPoint}'),\n },\n formats: ['es'],\n },\n rollupOptions: {\n external: (id) => {\n return (\n /^react($|\\\\/)/.test(id) ||\n /^react-dom($|\\\\/)/.test(id) ||\n /^@pie-lib\\\\//.test(id) ||\n /^@pie-element\\\\//.test(id) ||\n /^@pie-element\\\\//.test(id) ||\n /^@pie-framework\\\\//.test(id) ||\n /^@mui\\\\//.test(id) ||\n /^@emotion\\\\//.test(id) ||\n /^d3-/.test(id) ||\n /^@testing-library\\\\//.test(id) ||\n /^styled-components/.test(id) ||\n id === 'konva' || /^konva\\\\//.test(id) ||\n id === 'react-konva' || /^react-konva\\\\//.test(id) ||\n id === '@mdi/react' || /^@mdi\\\\/react\\\\//.test(id) ||\n id === '@mdi/js' || /^@mdi\\\\/js\\\\//.test(id) ||\n /^prosemirror-/.test(id) ||\n /^@tiptap\\\\//.test(id) ||\n ['prop-types', 'debug', 'i18next', 'humps', 'mathjs', 'react-jss', 'js-combinatorics', '@dnd-kit/core', 'react-transition-group'].includes(id)\n );\n },\n output: {\n preserveModules: true,\n preserveModulesRoot: 'src',\n },\n },\n },\n});\n`;\n }\n\n // Default pie-lib config\n return `import { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n // ESM-first resolution. A dependency with no exports map (@visx/* v3,\n // @hello-pangea/dnd) otherwise falls back to its CommonJS main entry, and\n // bundling CommonJS while React is external makes rolldown emit a\n // require(\"react\") shim that throws in the browser. Preferring the module\n // field resolves those dependencies to their ESM build instead.\n resolve: { mainFields: ['module', 'browser', 'main'] },\n plugins: [react()],\n build: {\n lib: {\n entry: {\n index: resolve(__dirname, '${entryPoint}'),\n },\n formats: ['es'],\n },\n rollupOptions: {\n external: ${createExternalFunction('pielib', {\n externalizeMathjs: packageName !== 'config-ui',\n })},\n output: {\n preserveModules: true,\n preserveModulesRoot: 'src',\n },\n },\n },\n});\n`;\n}\n"]}
|
|
@@ -58,6 +58,10 @@ export interface EsmRuntimeValidationResult {
|
|
|
58
58
|
* Compatibility report structure
|
|
59
59
|
*/
|
|
60
60
|
export interface CompatibilityReport {
|
|
61
|
+
browserEsmReady?: string[];
|
|
62
|
+
browserEsmUnsupported?: Record<string, {
|
|
63
|
+
reason: string;
|
|
64
|
+
}>;
|
|
61
65
|
elements: string[];
|
|
62
66
|
pieLibPackages: string[];
|
|
63
67
|
blockedElements: Record<string, string[]>;
|
|
@@ -86,6 +90,12 @@ export interface CompatibilityReport {
|
|
|
86
90
|
compatiblePieLibPackages: number;
|
|
87
91
|
};
|
|
88
92
|
}
|
|
93
|
+
export interface StaticBrowserEsmReport {
|
|
94
|
+
browserEsmReady: string[];
|
|
95
|
+
browserEsmUnsupported: Record<string, {
|
|
96
|
+
reason: string;
|
|
97
|
+
}>;
|
|
98
|
+
}
|
|
89
99
|
export interface ElementDetail {
|
|
90
100
|
compatible: boolean;
|
|
91
101
|
directDeps: string[];
|
|
@@ -110,6 +120,9 @@ export interface PieLibDetail {
|
|
|
110
120
|
usedBy: string[];
|
|
111
121
|
blockers: string[];
|
|
112
122
|
}
|
|
123
|
+
export declare function deriveStaticBrowserEsmReport(repoRoot: string): Promise<StaticBrowserEsmReport>;
|
|
124
|
+
export declare function formatCompatibilityReportLastAnalyzed(report: CompatibilityReport): string;
|
|
125
|
+
export declare function createTrackedCompatibilityReport(report: CompatibilityReport): CompatibilityReport;
|
|
113
126
|
export declare function loadCompatibilityReport(path: string): Promise<CompatibilityReport>;
|
|
114
127
|
export declare function isElementCompatible(element: string, report: CompatibilityReport): boolean;
|
|
115
128
|
export declare function isPieLibPackageCompatible(pkg: string, report: CompatibilityReport): boolean;
|
|
@@ -126,4 +139,3 @@ export declare function isElementStudentUIReady(element: string, report: Compati
|
|
|
126
139
|
* Get ESM validation details for an element
|
|
127
140
|
*/
|
|
128
141
|
export declare function getEsmValidation(element: string, report: CompatibilityReport): EsmValidationResult | null;
|
|
129
|
-
//# sourceMappingURL=compatibility.d.ts.map
|
|
@@ -1,11 +1,152 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function stringArray(value) {
|
|
8
|
+
return Array.isArray(value)
|
|
9
|
+
? value.filter((item) => typeof item === 'string')
|
|
10
|
+
: [];
|
|
11
|
+
}
|
|
12
|
+
function hasBrowserExport(exportsMap, key) {
|
|
13
|
+
if (!isRecord(exportsMap))
|
|
14
|
+
return false;
|
|
15
|
+
const value = exportsMap[key];
|
|
16
|
+
if (typeof value === 'string')
|
|
17
|
+
return value.length > 0;
|
|
18
|
+
return isRecord(value) && typeof value.default === 'string' && value.default.length > 0;
|
|
19
|
+
}
|
|
20
|
+
export async function deriveStaticBrowserEsmReport(repoRoot) {
|
|
21
|
+
const ready = [];
|
|
22
|
+
const unsupported = {};
|
|
23
|
+
const packageRoots = [
|
|
24
|
+
join(repoRoot, 'packages', 'elements-react'),
|
|
25
|
+
join(repoRoot, 'packages', 'elements-svelte'),
|
|
26
|
+
];
|
|
27
|
+
for (const packageRoot of packageRoots) {
|
|
28
|
+
const entries = await readdir(packageRoot, { withFileTypes: true }).catch(() => []);
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (!entry.isDirectory())
|
|
31
|
+
continue;
|
|
32
|
+
const packageJsonPath = join(packageRoot, entry.name, 'package.json');
|
|
33
|
+
if (!existsSync(packageJsonPath))
|
|
34
|
+
continue;
|
|
35
|
+
const pkg = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
|
|
36
|
+
if (pkg.private === true ||
|
|
37
|
+
typeof pkg.name !== 'string' ||
|
|
38
|
+
!pkg.name.startsWith('@pie-element/')) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const missing = ['./browser/delivery', './browser/controller'].filter((key) => !hasBrowserExport(pkg.exports, key));
|
|
42
|
+
if (missing.length === 0) {
|
|
43
|
+
ready.push(entry.name);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
unsupported[entry.name] = {
|
|
47
|
+
reason: `Missing browser ESM exports: ${missing.join(', ')}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
browserEsmReady: ready.sort(),
|
|
54
|
+
browserEsmUnsupported: Object.fromEntries(Object.entries(unsupported).sort()),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function blockedReason(value) {
|
|
58
|
+
if (typeof value === 'string') {
|
|
59
|
+
return [value];
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
const reasons = stringArray(value);
|
|
63
|
+
return reasons.length > 0 ? reasons : ['Unsupported by static browser ESM report'];
|
|
64
|
+
}
|
|
65
|
+
if (isRecord(value) && typeof value.reason === 'string') {
|
|
66
|
+
return [value.reason];
|
|
67
|
+
}
|
|
68
|
+
return ['Unsupported by static browser ESM report'];
|
|
69
|
+
}
|
|
70
|
+
function normalizeStaticBrowserEsmReport(report) {
|
|
71
|
+
const elements = stringArray(report.browserEsmReady);
|
|
72
|
+
const unsupported = isRecord(report.browserEsmUnsupported) ? report.browserEsmUnsupported : {};
|
|
73
|
+
const blockedElements = Object.fromEntries(Object.entries(unsupported).map(([element, details]) => [element, blockedReason(details)]));
|
|
74
|
+
const elementDetails = {};
|
|
75
|
+
for (const element of elements) {
|
|
76
|
+
elementDetails[element] = {
|
|
77
|
+
compatible: true,
|
|
78
|
+
directDeps: [],
|
|
79
|
+
pieLibDeps: [],
|
|
80
|
+
pieElementDeps: [],
|
|
81
|
+
blockers: [],
|
|
82
|
+
studentUI: { compatible: true, blockers: [] },
|
|
83
|
+
configure: { compatible: true, blockers: [] },
|
|
84
|
+
controller: { compatible: true, blockers: [] },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
for (const [element, blockers] of Object.entries(blockedElements)) {
|
|
88
|
+
elementDetails[element] = {
|
|
89
|
+
compatible: false,
|
|
90
|
+
directDeps: [],
|
|
91
|
+
pieLibDeps: [],
|
|
92
|
+
pieElementDeps: [],
|
|
93
|
+
blockers,
|
|
94
|
+
studentUI: { compatible: false, blockers },
|
|
95
|
+
configure: { compatible: false, blockers },
|
|
96
|
+
controller: { compatible: false, blockers },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...report,
|
|
101
|
+
elements,
|
|
102
|
+
pieLibPackages: [],
|
|
103
|
+
blockedElements,
|
|
104
|
+
elementDetails,
|
|
105
|
+
pieLibDetails: {},
|
|
106
|
+
esmPlayerReady: elements,
|
|
107
|
+
esmValidation: {},
|
|
108
|
+
lastAnalyzed: typeof report.lastAnalyzed === 'string' ? report.lastAnalyzed : 'unknown',
|
|
109
|
+
summary: {
|
|
110
|
+
totalElements: elements.length + Object.keys(blockedElements).length,
|
|
111
|
+
compatibleElements: elements.length,
|
|
112
|
+
blockedElements: Object.keys(blockedElements).length,
|
|
113
|
+
esmPlayerReady: elements.length,
|
|
114
|
+
totalPieLibPackages: 0,
|
|
115
|
+
compatiblePieLibPackages: 0,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function normalizeCompatibilityReport(report) {
|
|
120
|
+
if (isRecord(report) &&
|
|
121
|
+
Array.isArray(report.browserEsmReady) &&
|
|
122
|
+
!Array.isArray(report.elements)) {
|
|
123
|
+
return normalizeStaticBrowserEsmReport(report);
|
|
124
|
+
}
|
|
125
|
+
return report;
|
|
126
|
+
}
|
|
127
|
+
export function formatCompatibilityReportLastAnalyzed(report) {
|
|
128
|
+
const timestamp = report.lastAnalyzed;
|
|
129
|
+
if (!timestamp || timestamp === 'unknown') {
|
|
130
|
+
return 'unknown';
|
|
131
|
+
}
|
|
132
|
+
const analyzedAt = new Date(timestamp);
|
|
133
|
+
return Number.isNaN(analyzedAt.getTime()) ? 'unknown' : analyzedAt.toLocaleString();
|
|
134
|
+
}
|
|
135
|
+
export function createTrackedCompatibilityReport(report) {
|
|
136
|
+
const { esmRuntimeValidation, esmRuntimeValidationEnabled, esmRuntimeCdnBaseUrl, ...tracked } = report;
|
|
137
|
+
const { esmRuntimeReady, ...summary } = report.summary;
|
|
138
|
+
return {
|
|
139
|
+
...tracked,
|
|
140
|
+
lastAnalyzed: 'unknown',
|
|
141
|
+
summary,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
3
144
|
export async function loadCompatibilityReport(path) {
|
|
4
145
|
if (!existsSync(path)) {
|
|
5
146
|
throw new Error(`Compatibility report not found at: ${path}`);
|
|
6
147
|
}
|
|
7
148
|
const content = await readFile(path, 'utf-8');
|
|
8
|
-
return JSON.parse(content);
|
|
149
|
+
return normalizeCompatibilityReport(JSON.parse(content));
|
|
9
150
|
}
|
|
10
151
|
export function isElementCompatible(element, report) {
|
|
11
152
|
return report.elements.includes(element);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../../src/utils/compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAkIrC,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAY;IACxD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAwB,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,MAA2B;IAC9E,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,MAA2B;IAChF,OA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,CAAC,OAAO,CAAY,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,MAA2B;IAC9E,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,MAA2B;IAChF,OAAO,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,MAA2B;IAC7E,OAAO,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe,EAAE,MAA2B;IAClF,OAAO,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAe,EAAE,MAA2B;IAClF,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAE1B,2CAA2C;IAC3C,IAAI,MAAM,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAEnC,yDAAyD;IACzD,OAAO,MAAM,CAAC,SAAS,EAAE,UAAU,KAAK,IAAI,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAe,EACf,MAA2B;IAE3B,OAAO,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;AAC/C,CAAC","sourcesContent":["import { readFile, readdir } from 'node:fs/promises';\nimport { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/**\n * ESM package.json validation result\n */\nexport interface EsmPackageValidation {\n hasTypeModule: boolean;\n hasExportsField: boolean;\n hasMainExport: boolean;\n hasControllerExport: boolean;\n sideEffectsFree: boolean;\n mainExportIsEsm: boolean;\n controllerExportIsEsm: boolean;\n}\n\n/**\n * ESM player validation result for an element\n */\nexport interface EsmValidationResult {\n compatible: boolean;\n packageJson: EsmPackageValidation;\n blockers: string[];\n warnings: string[];\n}\n\n/**\n * Runtime-ish validation for ESM player readiness (CDN resolution / module parse).\n * Note: this is NOT a full browser execution test, but it provides production-like signal\n * by verifying CDN URLs resolve and the returned JS parses as an ES module.\n */\nexport interface EsmRuntimeValidationResult {\n /**\n * Whether this element passed the runtime-ish probe.\n * When false, see `errors` for details.\n */\n compatible: boolean;\n /** The CDN base URL used for probing (e.g. https://esm.sh). */\n cdnBaseUrl: string;\n /** Version that was probed (usually the upstream package.json version). */\n version: string;\n /** Whether the package entrypoint URL resolved (HTTP 200). */\n entryOk: boolean;\n /** Whether the controller URL resolved (HTTP 200). */\n controllerOk: boolean;\n /** Whether the returned JS for the entry parsed as an ES module. */\n entryParseOk: boolean;\n /** Whether the returned JS for the controller parsed as an ES module. */\n controllerParseOk: boolean;\n /** Any errors/warnings collected during probe. */\n errors: string[];\n\n /**\n * Probe details (for deep/transitive validation)\n */\n probeMode?: 'shallow' | 'deep';\n maxDepth?: number;\n maxModules?: number;\n fetchedModules?: number;\n fetchedOk?: number;\n firstFailingUrl?: string;\n}\n\n/**\n * Compatibility report structure\n */\nexport interface CompatibilityReport {\n browserEsmReady?: string[];\n browserEsmUnsupported?: Record<string, { reason: string }>;\n\n elements: string[];\n pieLibPackages: string[];\n blockedElements: Record<string, string[]>;\n elementDetails: Record<string, ElementDetail>;\n pieLibDetails: Record<string, PieLibDetail>;\n\n // ESM player validation\n esmPlayerReady: string[];\n esmValidation: Record<string, EsmValidationResult>;\n /**\n * Whether ESM player validation (package.json structure / exports) was run as part of analysis.\n * Optional for backwards compatibility with older reports.\n */\n esmPlayerValidationEnabled?: boolean;\n\n // Runtime-ish validation (CDN probes)\n esmRuntimeValidationEnabled?: boolean;\n esmRuntimeCdnBaseUrl?: string;\n esmRuntimeValidation?: Record<string, EsmRuntimeValidationResult>;\n\n // Student UI only (elements where student UI is ESM-ready but authoring isn't)\n studentUIOnly?: string[];\n\n lastAnalyzed: string;\n summary: {\n totalElements: number;\n compatibleElements: number;\n blockedElements: number;\n studentUIOnlyElements?: number;\n esmPlayerReady: number;\n esmRuntimeReady?: number;\n totalPieLibPackages: number;\n compatiblePieLibPackages: number;\n };\n}\n\nexport interface StaticBrowserEsmReport {\n browserEsmReady: string[];\n browserEsmUnsupported: Record<string, { reason: string }>;\n}\n\nexport interface ElementDetail {\n compatible: boolean;\n directDeps: string[];\n pieLibDeps: string[];\n pieElementDeps: string[];\n blockers: string[];\n\n // Separate analysis for student UI vs authoring\n studentUI?: {\n compatible: boolean;\n blockers: string[];\n };\n configure?: {\n compatible: boolean;\n blockers: string[];\n };\n controller?: {\n compatible: boolean;\n blockers: string[];\n };\n}\n\nexport interface PieLibDetail {\n compatible: boolean;\n usedBy: string[];\n blockers: string[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction stringArray(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((item): item is string => typeof item === 'string')\n : [];\n}\n\nfunction hasBrowserExport(exportsMap: unknown, key: string): boolean {\n if (!isRecord(exportsMap)) return false;\n const value = exportsMap[key];\n if (typeof value === 'string') return value.length > 0;\n return isRecord(value) && typeof value.default === 'string' && value.default.length > 0;\n}\n\nexport async function deriveStaticBrowserEsmReport(\n repoRoot: string\n): Promise<StaticBrowserEsmReport> {\n const ready: string[] = [];\n const unsupported: Record<string, { reason: string }> = {};\n const packageRoots = [\n join(repoRoot, 'packages', 'elements-react'),\n join(repoRoot, 'packages', 'elements-svelte'),\n ];\n\n for (const packageRoot of packageRoots) {\n const entries = await readdir(packageRoot, { withFileTypes: true }).catch(() => []);\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const packageJsonPath = join(packageRoot, entry.name, 'package.json');\n if (!existsSync(packageJsonPath)) continue;\n\n const pkg = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as Record<string, unknown>;\n if (\n pkg.private === true ||\n typeof pkg.name !== 'string' ||\n !pkg.name.startsWith('@pie-element/')\n ) {\n continue;\n }\n\n const missing = ['./browser/delivery', './browser/controller'].filter(\n (key) => !hasBrowserExport(pkg.exports, key)\n );\n if (missing.length === 0) {\n ready.push(entry.name);\n } else {\n unsupported[entry.name] = {\n reason: `Missing browser ESM exports: ${missing.join(', ')}`,\n };\n }\n }\n }\n\n return {\n browserEsmReady: ready.sort(),\n browserEsmUnsupported: Object.fromEntries(Object.entries(unsupported).sort()),\n };\n}\n\nfunction blockedReason(value: unknown): string[] {\n if (typeof value === 'string') {\n return [value];\n }\n if (Array.isArray(value)) {\n const reasons = stringArray(value);\n return reasons.length > 0 ? reasons : ['Unsupported by static browser ESM report'];\n }\n if (isRecord(value) && typeof value.reason === 'string') {\n return [value.reason];\n }\n return ['Unsupported by static browser ESM report'];\n}\n\nfunction normalizeStaticBrowserEsmReport(report: Record<string, unknown>): CompatibilityReport {\n const elements = stringArray(report.browserEsmReady);\n const unsupported = isRecord(report.browserEsmUnsupported) ? report.browserEsmUnsupported : {};\n const blockedElements = Object.fromEntries(\n Object.entries(unsupported).map(([element, details]) => [element, blockedReason(details)])\n );\n const elementDetails: Record<string, ElementDetail> = {};\n\n for (const element of elements) {\n elementDetails[element] = {\n compatible: true,\n directDeps: [],\n pieLibDeps: [],\n pieElementDeps: [],\n blockers: [],\n studentUI: { compatible: true, blockers: [] },\n configure: { compatible: true, blockers: [] },\n controller: { compatible: true, blockers: [] },\n };\n }\n\n for (const [element, blockers] of Object.entries(blockedElements)) {\n elementDetails[element] = {\n compatible: false,\n directDeps: [],\n pieLibDeps: [],\n pieElementDeps: [],\n blockers,\n studentUI: { compatible: false, blockers },\n configure: { compatible: false, blockers },\n controller: { compatible: false, blockers },\n };\n }\n\n return {\n ...report,\n elements,\n pieLibPackages: [],\n blockedElements,\n elementDetails,\n pieLibDetails: {},\n esmPlayerReady: elements,\n esmValidation: {},\n lastAnalyzed: typeof report.lastAnalyzed === 'string' ? report.lastAnalyzed : 'unknown',\n summary: {\n totalElements: elements.length + Object.keys(blockedElements).length,\n compatibleElements: elements.length,\n blockedElements: Object.keys(blockedElements).length,\n esmPlayerReady: elements.length,\n totalPieLibPackages: 0,\n compatiblePieLibPackages: 0,\n },\n };\n}\n\nfunction normalizeCompatibilityReport(report: unknown): CompatibilityReport {\n if (\n isRecord(report) &&\n Array.isArray(report.browserEsmReady) &&\n !Array.isArray(report.elements)\n ) {\n return normalizeStaticBrowserEsmReport(report);\n }\n\n return report as CompatibilityReport;\n}\n\nexport function formatCompatibilityReportLastAnalyzed(report: CompatibilityReport): string {\n const timestamp = report.lastAnalyzed;\n if (!timestamp || timestamp === 'unknown') {\n return 'unknown';\n }\n\n const analyzedAt = new Date(timestamp);\n return Number.isNaN(analyzedAt.getTime()) ? 'unknown' : analyzedAt.toLocaleString();\n}\n\nexport function createTrackedCompatibilityReport(report: CompatibilityReport): CompatibilityReport {\n const { esmRuntimeValidation, esmRuntimeValidationEnabled, esmRuntimeCdnBaseUrl, ...tracked } =\n report;\n const { esmRuntimeReady, ...summary } = report.summary;\n\n return {\n ...tracked,\n lastAnalyzed: 'unknown',\n summary,\n };\n}\n\nexport async function loadCompatibilityReport(path: string): Promise<CompatibilityReport> {\n if (!existsSync(path)) {\n throw new Error(`Compatibility report not found at: ${path}`);\n }\n\n const content = await readFile(path, 'utf-8');\n return normalizeCompatibilityReport(JSON.parse(content) as unknown);\n}\n\nexport function isElementCompatible(element: string, report: CompatibilityReport): boolean {\n return report.elements.includes(element);\n}\n\nexport function isPieLibPackageCompatible(pkg: string, report: CompatibilityReport): boolean {\n return report.pieLibPackages.includes(pkg);\n}\n\nexport function getElementBlockers(element: string, report: CompatibilityReport): string[] {\n return report.blockedElements[element] || [];\n}\n\n/**\n * Check if an element is ESM player ready (no CommonJS deps + proper ESM package structure)\n */\nexport function isElementEsmPlayerReady(element: string, report: CompatibilityReport): boolean {\n return report.esmPlayerReady.includes(element);\n}\n\n/**\n * Check if an element has student UI ready (even if configure/controller aren't)\n */\nexport function isElementStudentUIReady(element: string, report: CompatibilityReport): boolean {\n const detail = report.elementDetails[element];\n if (!detail) return false;\n\n // If fully compatible, student UI is ready\n if (detail.compatible) return true;\n\n // Check if student UI is explicitly marked as compatible\n return detail.studentUI?.compatible === true;\n}\n\n/**\n * Get ESM validation details for an element\n */\nexport function getEsmValidation(\n element: string,\n report: CompatibilityReport\n): EsmValidationResult | null {\n return report.esmValidation[element] || null;\n}\n"]}
|
|
@@ -22,4 +22,3 @@ export declare function convertJsxToTsx(jsxCode: string, metadata: ConversionMet
|
|
|
22
22
|
* Some files export default objects but are imported with named imports
|
|
23
23
|
*/
|
|
24
24
|
export declare function fixImports(content: string, hasDefaultObjectExport: boolean): string;
|
|
25
|
-
//# sourceMappingURL=conversion.d.ts.map
|