@pie-element/cli 0.1.2-next.2 → 0.1.2-next.20261002100925
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 +5 -5
- package/dist/commands/packages/create-react-elements.js +12 -31
- package/dist/commands/packages/create-react-elements.js.map +1 -1
- package/dist/commands/packages/init-synced-elements.js +3 -5
- package/dist/commands/packages/init-synced-elements.js.map +1 -1
- package/dist/commands/upstream/analyze-esm.js +1 -34
- package/dist/commands/upstream/analyze-esm.js.map +1 -1
- package/dist/commands/upstream/sync.js +10 -15
- package/dist/commands/upstream/sync.js.map +1 -1
- package/dist/lib/upstream/editor-runtime.d.ts +15 -0
- package/dist/lib/upstream/editor-runtime.js +55 -0
- package/dist/lib/upstream/editor-runtime.js.map +1 -0
- package/dist/lib/upstream/sync-compatibility.d.ts +0 -8
- package/dist/lib/upstream/sync-compatibility.js +0 -31
- package/dist/lib/upstream/sync-compatibility.js.map +1 -1
- package/dist/lib/upstream/sync-constants.d.ts +20 -12
- package/dist/lib/upstream/sync-constants.js +50 -15
- package/dist/lib/upstream/sync-constants.js.map +1 -1
- package/dist/lib/upstream/sync-demo-metadata.js +117 -109
- package/dist/lib/upstream/sync-demo-metadata.js.map +1 -1
- package/dist/lib/upstream/sync-imports.d.ts +14 -21
- package/dist/lib/upstream/sync-imports.js +106 -77
- package/dist/lib/upstream/sync-imports.js.map +1 -1
- package/dist/lib/upstream/sync-package-json.d.ts +0 -19
- package/dist/lib/upstream/sync-package-json.js +0 -58
- package/dist/lib/upstream/sync-package-json.js.map +1 -1
- package/dist/lib/upstream/sync-package-manager.d.ts +6 -0
- package/dist/lib/upstream/sync-package-manager.js +84 -31
- package/dist/lib/upstream/sync-package-manager.js.map +1 -1
- package/dist/lib/upstream/sync-presets.d.ts +2 -0
- package/dist/lib/upstream/sync-presets.js +34 -0
- package/dist/lib/upstream/sync-presets.js.map +1 -1
- package/dist/lib/upstream/sync-react-strategy.js +3 -3
- package/dist/lib/upstream/sync-react-strategy.js.map +1 -1
- package/dist/lib/upstream/sync-source-tree.js +3 -1
- package/dist/lib/upstream/sync-source-tree.js.map +1 -1
- package/dist/lib/upstream/sync-transforms.d.ts +2 -2
- package/dist/lib/upstream/sync-transforms.js +5 -3
- package/dist/lib/upstream/sync-transforms.js.map +1 -1
- package/dist/lib/upstream/sync-vite-config.d.ts +0 -4
- package/dist/lib/upstream/sync-vite-config.js +1 -12
- package/dist/lib/upstream/sync-vite-config.js.map +1 -1
- package/dist/lib/upstream/workspace-pie-lib.d.ts +2 -0
- package/dist/lib/upstream/workspace-pie-lib.js +29 -0
- package/dist/lib/upstream/workspace-pie-lib.js.map +1 -0
- package/dist/utils/compatibility.d.ts +0 -15
- package/dist/utils/compatibility.js +0 -34
- package/dist/utils/compatibility.js.map +1 -1
- package/dist/utils/conversion.d.ts +0 -5
- package/dist/utils/conversion.js +0 -21
- package/dist/utils/conversion.js.map +1 -1
- package/dist/utils/git.d.ts +0 -1
- package/dist/utils/git.js +0 -8
- package/dist/utils/git.js.map +1 -1
- package/package.json +2 -2
|
@@ -208,75 +208,6 @@ const ${importName} = {
|
|
|
208
208
|
};`;
|
|
209
209
|
return code.replace(configureImportRegex, inlinedDefaults);
|
|
210
210
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Determine if a file should have .tsx extension based on content
|
|
213
|
-
*/
|
|
214
|
-
export function shouldUseTsxExtension(content, originalPath) {
|
|
215
|
-
// If original file was .jsx, use .tsx
|
|
216
|
-
if (originalPath.endsWith('.jsx')) {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
// If content contains JSX, use .tsx
|
|
220
|
-
if (containsJsx(content)) {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
// Otherwise use .ts
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Convert CommonJS module.exports to ES module exports
|
|
228
|
-
*
|
|
229
|
-
* Handles patterns like:
|
|
230
|
-
* module.exports = { foo: ..., bar: ... }
|
|
231
|
-
*
|
|
232
|
-
* Converts to:
|
|
233
|
-
* export const foo = ...;
|
|
234
|
-
* export const bar = ...;
|
|
235
|
-
*/
|
|
236
|
-
export function convertModuleExportsToEsm(content) {
|
|
237
|
-
// Match: module.exports = { key: value, key2: value2, ... };
|
|
238
|
-
const moduleExportsPattern = /module\.exports\s*=\s*\{([\s\S]*?)\};?/;
|
|
239
|
-
const match = content.match(moduleExportsPattern);
|
|
240
|
-
if (!match) {
|
|
241
|
-
return content;
|
|
242
|
-
}
|
|
243
|
-
const [fullMatch, objectContent] = match;
|
|
244
|
-
// Parse the object content into key-value pairs
|
|
245
|
-
// Match patterns like: key: value, (with value possibly spanning multiple lines)
|
|
246
|
-
const exports = [];
|
|
247
|
-
const lines = objectContent.split('\n');
|
|
248
|
-
let currentKey = null;
|
|
249
|
-
let currentValue = [];
|
|
250
|
-
for (const line of lines) {
|
|
251
|
-
const trimmed = line.trim();
|
|
252
|
-
if (!trimmed || trimmed === '{' || trimmed === '}')
|
|
253
|
-
continue;
|
|
254
|
-
// Check if this line starts a new key
|
|
255
|
-
const keyMatch = trimmed.match(/^(\w+):\s*(.*)/);
|
|
256
|
-
if (keyMatch) {
|
|
257
|
-
// Save previous export if any
|
|
258
|
-
if (currentKey) {
|
|
259
|
-
const value = currentValue.join('\n').replace(/,\s*$/, ''); // Remove trailing comma
|
|
260
|
-
exports.push(`export const ${currentKey} =\n${value};`);
|
|
261
|
-
}
|
|
262
|
-
// Start new export
|
|
263
|
-
currentKey = keyMatch[1];
|
|
264
|
-
currentValue = [keyMatch[2]];
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
// Continuation of current value
|
|
268
|
-
currentValue.push(line);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// Save last export
|
|
272
|
-
if (currentKey) {
|
|
273
|
-
const value = currentValue.join('\n').replace(/,\s*$/, '');
|
|
274
|
-
exports.push(`export const ${currentKey} =\n${value};`);
|
|
275
|
-
}
|
|
276
|
-
// Replace the module.exports block with ES module exports
|
|
277
|
-
const esmExports = exports.join('\n\n');
|
|
278
|
-
return content.replace(fullMatch, esmExports);
|
|
279
|
-
}
|
|
280
211
|
const VENDORED_LODASH_PACKAGE = '@pie-element/shared-lodash';
|
|
281
212
|
function lodashMemberFromPath(path) {
|
|
282
213
|
return path.replace(/\.js$/i, '').split('/').pop() ?? path;
|
|
@@ -412,7 +343,6 @@ function lodashExportSpecifierBinding(member, specifier) {
|
|
|
412
343
|
function formatLodashBinding(imported, local) {
|
|
413
344
|
return imported === local ? imported : `${imported} as ${local}`;
|
|
414
345
|
}
|
|
415
|
-
export const transformLodashToLodashEs = transformLodashToVendoredLodash;
|
|
416
346
|
/**
|
|
417
347
|
* Transform classnames imports to clsx.
|
|
418
348
|
*
|
|
@@ -422,6 +352,112 @@ export const transformLodashToLodashEs = transformLodashToVendoredLodash;
|
|
|
422
352
|
export function transformClassnamesToClsx(content) {
|
|
423
353
|
return rewriteModuleSpecifiers(content, (specifier) => specifier === 'classnames' ? 'clsx' : undefined);
|
|
424
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Rewrite js-combinatorics 0.5 `combination(seed, size)` calls to the 2.x `Combination` class.
|
|
357
|
+
*
|
|
358
|
+
* Upstream depends on 0.5, a UMD script with no ESM entrypoint; synced packages depend on 2.x,
|
|
359
|
+
* where `combination(n, k)` counts combinations as a BigInt and throws when given an array.
|
|
360
|
+
* `new Combination(seed, size)` enumerates the same pairs in the same order.
|
|
361
|
+
*/
|
|
362
|
+
export function transformJsCombinatoricsToV2(content) {
|
|
363
|
+
if (!content.includes('js-combinatorics')) {
|
|
364
|
+
return content;
|
|
365
|
+
}
|
|
366
|
+
const sourceFile = ts.createSourceFile('source.tsx', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
367
|
+
const edits = [];
|
|
368
|
+
const callees = new Map();
|
|
369
|
+
for (const statement of sourceFile.statements) {
|
|
370
|
+
if (!ts.isImportDeclaration(statement) ||
|
|
371
|
+
!ts.isStringLiteral(statement.moduleSpecifier) ||
|
|
372
|
+
statement.moduleSpecifier.text !== 'js-combinatorics') {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const bindings = statement.importClause?.namedBindings;
|
|
376
|
+
if (!bindings || !ts.isNamedImports(bindings)) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
for (const element of bindings.elements) {
|
|
380
|
+
if ((element.propertyName ?? element.name).text !== 'combination') {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
const local = element.name.text;
|
|
384
|
+
const aliased = local !== 'combination';
|
|
385
|
+
callees.set(local, aliased ? local : 'Combination');
|
|
386
|
+
edits.push({
|
|
387
|
+
start: element.getStart(sourceFile),
|
|
388
|
+
end: element.getEnd(),
|
|
389
|
+
text: aliased ? `Combination as ${local}` : 'Combination',
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (callees.size === 0) {
|
|
394
|
+
return content;
|
|
395
|
+
}
|
|
396
|
+
const visit = (node) => {
|
|
397
|
+
if (ts.isCallExpression(node) &&
|
|
398
|
+
ts.isIdentifier(node.expression) &&
|
|
399
|
+
callees.has(node.expression.text)) {
|
|
400
|
+
edits.push({
|
|
401
|
+
start: node.expression.getStart(sourceFile),
|
|
402
|
+
end: node.expression.getEnd(),
|
|
403
|
+
text: `new ${callees.get(node.expression.text)}`,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
ts.forEachChild(node, visit);
|
|
407
|
+
};
|
|
408
|
+
visit(sourceFile);
|
|
409
|
+
return applySourceEdits(content, edits);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* CommonJS packages whose exports Node's ESM loader cannot detect, mapped to the binding the
|
|
413
|
+
* rewrite imports them as. A named import from one of them fails to link when a host imports
|
|
414
|
+
* the built controller in Node; a default import is `module.exports` in Node and in bundlers.
|
|
415
|
+
*/
|
|
416
|
+
const COMMONJS_DEFAULT_IMPORTS = {
|
|
417
|
+
humps: 'humps',
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Rewrite named imports from COMMONJS_DEFAULT_IMPORTS packages to a default import plus a
|
|
421
|
+
* destructure, so `import { camelizeKeys } from 'humps'` becomes
|
|
422
|
+
* `import humps from 'humps'; const { camelizeKeys } = humps;`.
|
|
423
|
+
*/
|
|
424
|
+
export function transformCommonJsNamedImports(content) {
|
|
425
|
+
if (!Object.keys(COMMONJS_DEFAULT_IMPORTS).some((name) => content.includes(name))) {
|
|
426
|
+
return content;
|
|
427
|
+
}
|
|
428
|
+
const sourceFile = ts.createSourceFile('source.tsx', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
429
|
+
const edits = [];
|
|
430
|
+
for (const statement of sourceFile.statements) {
|
|
431
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const specifier = statement.moduleSpecifier.text;
|
|
435
|
+
if (!Object.hasOwn(COMMONJS_DEFAULT_IMPORTS, specifier)) {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const clause = statement.importClause;
|
|
439
|
+
const bindings = clause?.namedBindings;
|
|
440
|
+
if (!clause ||
|
|
441
|
+
clause.isTypeOnly ||
|
|
442
|
+
!bindings ||
|
|
443
|
+
!ts.isNamedImports(bindings) ||
|
|
444
|
+
bindings.elements.length === 0 ||
|
|
445
|
+
bindings.elements.some((element) => element.isTypeOnly)) {
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const moduleBinding = clause.name?.text ?? COMMONJS_DEFAULT_IMPORTS[specifier];
|
|
449
|
+
const properties = bindings.elements.map((element) => element.propertyName
|
|
450
|
+
? `${element.propertyName.text}: ${element.name.text}`
|
|
451
|
+
: element.name.text);
|
|
452
|
+
const quoted = quoteLike(specifier, statement.moduleSpecifier.getText(sourceFile));
|
|
453
|
+
edits.push({
|
|
454
|
+
start: statement.getStart(sourceFile),
|
|
455
|
+
end: statement.getEnd(),
|
|
456
|
+
text: `import ${moduleBinding} from ${quoted};\nconst { ${properties.join(', ')} } = ${moduleBinding};`,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
return applySourceEdits(content, edits);
|
|
460
|
+
}
|
|
425
461
|
/**
|
|
426
462
|
* Replace react-input-autosize with the local ESM autosize input component.
|
|
427
463
|
*
|
|
@@ -511,13 +547,6 @@ export function transformConfigUiMathjsToLocalFraction(content, sourcePath) {
|
|
|
511
547
|
}
|
|
512
548
|
return transformed;
|
|
513
549
|
}
|
|
514
|
-
/**
|
|
515
|
-
* Compatibility wrapper retained for older callers. Lodash imports now target
|
|
516
|
-
* the vendored shared package rather than lodash-es deep modules.
|
|
517
|
-
*/
|
|
518
|
-
export function transformLodashEsDeepImportsToFullySpecified(content) {
|
|
519
|
-
return transformLodashToVendoredLodash(content);
|
|
520
|
-
}
|
|
521
550
|
/**
|
|
522
551
|
* Ensure known strict-ESM deep imports include explicit file extensions.
|
|
523
552
|
*
|