@plasmicapp/cli 0.1.345 → 0.1.346

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/index.js CHANGED
@@ -488191,7 +488191,7 @@ async function formatAsLocal(content, filePath, baseDir, defaultOpts) {
488191
488191
  async function nodeToFormattedCode(n26, baseDir, unformatted, commentsToRemove) {
488192
488192
  const c5 = (0, import_generator.default)(n26, {
488193
488193
  retainLines: true,
488194
- shouldPrintComment: (c7) => !commentsToRemove || !commentsToRemove.has(c7)
488194
+ shouldPrintComment: (comment) => !commentsToRemove || !commentsToRemove.has(comment)
488195
488195
  }).code;
488196
488196
  return unformatted ? c5 : await formatAsLocal(c5, "/tmp/x.tsx", baseDir, {
488197
488197
  arrowParens: "avoid"
@@ -488259,6 +488259,7 @@ function tryParsePlasmicImportSpec(node) {
488259
488259
  return void 0;
488260
488260
  }
488261
488261
  const m5 = c5.value.match(
488262
+ // eslint-disable-next-line no-misleading-character-class
488262
488263
  new RegExp(
488263
488264
  [
488264
488265
  "plasmic-import:\\s+([",
@@ -488321,7 +488322,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488321
488322
  ensureImportSpecifierWithAlias(stmt, exportName, compConfig.name);
488322
488323
  } else {
488323
488324
  }
488324
- const realPath = makeImportPath(context, fromPath, modulePath, true);
488325
+ const realPath = makeImportPath(context, fromPath, modulePath);
488325
488326
  stmt.source.value = realPath;
488326
488327
  } else if (type === "render") {
488327
488328
  const compConfig = fixImportContext.components[uuid];
@@ -488331,8 +488332,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488331
488332
  const realPath = makeImportPath(
488332
488333
  context,
488333
488334
  fromPath,
488334
- compConfig.renderModuleFilePath,
488335
- true
488335
+ compConfig.renderModuleFilePath
488336
488336
  );
488337
488337
  stmt.source.value = realPath;
488338
488338
  } else if (type === "css") {
@@ -488343,8 +488343,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488343
488343
  const realPath = makeImportPath(
488344
488344
  context,
488345
488345
  fromPath,
488346
- compConfig.cssFilePath,
488347
- false
488346
+ compConfig.cssFilePath
488348
488347
  );
488349
488348
  stmt.source.value = realPath;
488350
488349
  } else if (type === "globalVariant") {
@@ -488355,8 +488354,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488355
488354
  const realPath = makeImportPath(
488356
488355
  context,
488357
488356
  fromPath,
488358
- variantConfig.contextFilePath,
488359
- true
488357
+ variantConfig.contextFilePath
488360
488358
  );
488361
488359
  stmt.source.value = realPath;
488362
488360
  } else if (type === "icon") {
@@ -488367,8 +488365,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488367
488365
  const realPath = makeImportPath(
488368
488366
  context,
488369
488367
  fromPath,
488370
- iconConfig.moduleFilePath,
488371
- true
488368
+ iconConfig.moduleFilePath
488372
488369
  );
488373
488370
  stmt.source.value = realPath;
488374
488371
  } else if (type === "picture") {
@@ -488376,12 +488373,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488376
488373
  if (!imageConfig) {
488377
488374
  throwMissingReference(context, "image", uuid, fromPath);
488378
488375
  }
488379
- const realPath = makeImportPath(
488380
- context,
488381
- fromPath,
488382
- imageConfig.filePath,
488383
- false
488384
- );
488376
+ const realPath = makeImportPath(context, fromPath, imageConfig.filePath);
488385
488377
  stmt.source.value = realPath;
488386
488378
  } else if (type === "projectcss") {
488387
488379
  const projectConfig = fixImportContext.projects[uuid];
@@ -488391,16 +488383,14 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488391
488383
  const realPath = makeImportPath(
488392
488384
  context,
488393
488385
  fromPath,
488394
- projectConfig.cssFilePath,
488395
- false
488386
+ projectConfig.cssFilePath
488396
488387
  );
488397
488388
  stmt.source.value = realPath;
488398
488389
  } else if (type === "defaultcss") {
488399
488390
  const realPath = makeImportPath(
488400
488391
  context,
488401
488392
  fromPath,
488402
- fixImportContext.config.style.defaultStyleCssFilePath,
488403
- false
488393
+ fixImportContext.config.style.defaultStyleCssFilePath
488404
488394
  );
488405
488395
  stmt.source.value = realPath;
488406
488396
  } else if (type === "codeComponent") {
@@ -488413,7 +488403,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488413
488403
  if (meta.componentImportPath[0] === ".") {
488414
488404
  const toPath2 = import_upath2.default.join(context.rootDir, meta.componentImportPath);
488415
488405
  assert6(import_upath2.default.isAbsolute(toPath2));
488416
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
488406
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
488417
488407
  stmt.source.value = realPath;
488418
488408
  } else {
488419
488409
  stmt.source.value = meta.componentImportPath;
@@ -488428,7 +488418,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488428
488418
  if (meta.helper.importPath[0] === ".") {
488429
488419
  const toPath2 = import_upath2.default.join(context.rootDir, meta.helper.importPath);
488430
488420
  assert6(import_upath2.default.isAbsolute(toPath2));
488431
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
488421
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
488432
488422
  stmt.source.value = realPath;
488433
488423
  } else {
488434
488424
  stmt.source.value = meta.helper.importPath;
@@ -488441,8 +488431,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488441
488431
  const realPath = makeImportPath(
488442
488432
  context,
488443
488433
  fromPath,
488444
- projectConfig.globalContextsFilePath,
488445
- true
488434
+ projectConfig.globalContextsFilePath
488446
488435
  );
488447
488436
  stmt.source.value = realPath;
488448
488437
  } else if (type === "customFunction") {
@@ -488455,7 +488444,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488455
488444
  if (meta.importPath[0] === ".") {
488456
488445
  const toPath2 = import_upath2.default.join(context.rootDir, meta.importPath);
488457
488446
  assert6(import_upath2.default.isAbsolute(toPath2));
488458
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
488447
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
488459
488448
  stmt.source.value = realPath;
488460
488449
  } else {
488461
488450
  stmt.source.value = meta.importPath;
@@ -488468,8 +488457,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488468
488457
  const realPath = makeImportPath(
488469
488458
  context,
488470
488459
  fromPath,
488471
- projectConfig.splitsProviderFilePath,
488472
- true
488460
+ projectConfig.splitsProviderFilePath
488473
488461
  );
488474
488462
  stmt.source.value = realPath;
488475
488463
  } else if (type === "styleTokensProvider") {
@@ -488480,8 +488468,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488480
488468
  const realPath = makeImportPath(
488481
488469
  context,
488482
488470
  fromPath,
488483
- projectConfig.styleTokensProviderFilePath,
488484
- true
488471
+ projectConfig.styleTokensProviderFilePath
488485
488472
  );
488486
488473
  stmt.source.value = realPath;
488487
488474
  } else if (type === "projectModule") {
@@ -488492,8 +488479,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488492
488479
  const realPath = makeImportPath(
488493
488480
  context,
488494
488481
  fromPath,
488495
- projectConfig.projectModuleFilePath,
488496
- true
488482
+ projectConfig.projectModuleFilePath
488497
488483
  );
488498
488484
  stmt.source.value = realPath;
488499
488485
  } else if (type === "rscClient") {
@@ -488507,12 +488493,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488507
488493
  `Encountered Plasmic component "${uuid}" that is missing a rscClientModulePath.`
488508
488494
  );
488509
488495
  }
488510
- stmt.source.value = makeImportPath(
488511
- context,
488512
- fromPath,
488513
- clientModulePath,
488514
- true
488515
- );
488496
+ stmt.source.value = makeImportPath(context, fromPath, clientModulePath);
488516
488497
  } else if (type === "rscServer") {
488517
488498
  const compConfig = fixImportContext.components[uuid];
488518
488499
  if (!compConfig) {
@@ -488527,12 +488508,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
488527
488508
  logger.info(
488528
488509
  `Fixing "rscServer" with "${serverModulePath}" and from "${fromPath}"`
488529
488510
  );
488530
- stmt.source.value = makeImportPath(
488531
- context,
488532
- fromPath,
488533
- serverModulePath,
488534
- true
488535
- );
488511
+ stmt.source.value = makeImportPath(context, fromPath, serverModulePath);
488536
488512
  }
488537
488513
  });
488538
488514
  if (!changed) {
@@ -488551,8 +488527,17 @@ function throwMissingReference(context, itemType, uuid, fromPath) {
488551
488527
  `Encountered Plasmic ${itemType} "${uuid}" in ${fromPath} that are being used but have not been synced. ${recFix}`
488552
488528
  );
488553
488529
  }
488554
- function makeImportPath(context, fromPath, toPath2, stripExt, forceRelative = false) {
488530
+ function makeImportPath(context, fromPath, toPath2, forceRelative = false) {
488555
488531
  let result = toPath2;
488532
+ const stripExt = context.config.preserveJsImportExtensions ? (
488533
+ // Do not strip any extensions if the user has explicitly requested to preserve them
488534
+ false
488535
+ ) : (
488536
+ // Strip extensions only for JavaScript/TypeScript modules
488537
+ [".ts", ".tsx", ".js", ".jsx"].includes(
488538
+ import_upath2.default.extname(toPath2).toLowerCase()
488539
+ )
488540
+ );
488556
488541
  if (forceRelative || isLocalModulePath(toPath2)) {
488557
488542
  result = import_upath2.default.relative(
488558
488543
  makeFilePath(context, import_upath2.default.dirname(fromPath)),
@@ -488800,7 +488785,7 @@ var tsxToJsx = (code) => {
488800
488785
  str = str.replace(usageMagic, "");
488801
488786
  return str;
488802
488787
  }
488803
- let result = ts7.transpileModule(prepForTranspile(code), {
488788
+ const result = ts7.transpileModule(prepForTranspile(code), {
488804
488789
  compilerOptions: CompilerOptions.getOpts()
488805
488790
  });
488806
488791
  return fixPostTranspile(result.outputText);
@@ -488824,10 +488809,10 @@ async function formatScript(code, baseDir) {
488824
488809
  newLineMarker = newLineMarker + "_REALLY";
488825
488810
  }
488826
488811
  (0, import_traverse.default)(file, {
488827
- Statement: function(path28) {
488828
- if (file.program.body.includes(path28.node) && path28.node.type !== "ImportDeclaration") {
488829
- path28.insertBefore(babel.types.stringLiteral(newLineMarker));
488830
- path28.skip();
488812
+ Statement: function(filePath) {
488813
+ if (file.program.body.includes(filePath.node) && filePath.node.type !== "ImportDeclaration") {
488814
+ filePath.insertBefore(babel.types.stringLiteral(newLineMarker));
488815
+ filePath.skip();
488831
488816
  }
488832
488817
  }
488833
488818
  });
@@ -488844,8 +488829,9 @@ async function formatScript(code, baseDir) {
488844
488829
  }
488845
488830
  async function fixGlobalContextImportStatements(context, fixImportContext, baseDir) {
488846
488831
  for (const project of context.config.projects) {
488847
- if (!project.globalContextsFilePath)
488832
+ if (!project.globalContextsFilePath) {
488848
488833
  continue;
488834
+ }
488849
488835
  const resourcePath = getGlobalContextsResourcePath(context, project);
488850
488836
  let prevContent;
488851
488837
  try {
@@ -488876,8 +488862,9 @@ async function fixGlobalContextImportStatements(context, fixImportContext, baseD
488876
488862
  }
488877
488863
  async function fixImportStatements(context, fixImportContext, baseDir, configKey, getResourcePath) {
488878
488864
  for (const project of context.config.projects) {
488879
- if (!project[configKey])
488865
+ if (!project[configKey]) {
488880
488866
  continue;
488867
+ }
488881
488868
  const resourcePath = getResourcePath(context, project);
488882
488869
  let prevContent;
488883
488870
  try {
@@ -489586,7 +489573,8 @@ var DEFAULT_CONFIG = {
489586
489573
  globalVariants: {
489587
489574
  variantGroups: []
489588
489575
  },
489589
- wrapPagesWithGlobalContexts: true
489576
+ wrapPagesWithGlobalContexts: true,
489577
+ preserveJsImportExtensions: false
489590
489578
  };
489591
489579
  var DEFAULT_PUBLIC_FILES_CONFIG = {
489592
489580
  scheme: "public-files",
@@ -489657,7 +489645,7 @@ async function updateConfig(context, newConfig, baseDir) {
489657
489645
  function getOrAddProjectConfig(context, projectId, base) {
489658
489646
  let project = context.config.projects.find((p5) => p5.projectId === projectId);
489659
489647
  if (!project) {
489660
- project = !!base ? import_lodash9.default.cloneDeep(base) : {
489648
+ project = base ? import_lodash9.default.cloneDeep(base) : {
489661
489649
  projectId,
489662
489650
  projectName: "",
489663
489651
  version: "latest",
@@ -489678,7 +489666,7 @@ function getOrAddProjectConfig(context, projectId, base) {
489678
489666
  function getOrAddProjectLock(context, projectId, branchName, base) {
489679
489667
  let project = context.lock.projects.find((p5) => p5.projectId === projectId);
489680
489668
  if (!project) {
489681
- project = !!base ? import_lodash9.default.cloneDeep(base) : {
489669
+ project = base ? import_lodash9.default.cloneDeep(base) : {
489682
489670
  projectId,
489683
489671
  branchName,
489684
489672
  version: "",
@@ -491389,6 +491377,7 @@ async function exportProjectsCli(opts) {
491389
491377
  platform: opts.platform || "react",
491390
491378
  srcDir: "./",
491391
491379
  defaultPlasmicDir: "./",
491380
+ preserveJsImportExtensions: false,
491392
491381
  code: {
491393
491382
  lang: opts.codeLang || "ts",
491394
491383
  scheme: "blackbox",
@@ -492730,8 +492719,9 @@ async function ensureRequiredPackages(context, baseDir, yes) {
492730
492719
  }
492731
492720
  }
492732
492721
  async function sync(opts, metadataDefaults) {
492733
- if (!opts.baseDir)
492722
+ if (!opts.baseDir) {
492734
492723
  opts.baseDir = process.cwd();
492724
+ }
492735
492725
  const baseDir = opts.baseDir;
492736
492726
  let context = await getContext(opts, { enableSkipAuth: true });
492737
492727
  if (opts.skipFormatting) {
@@ -492931,14 +492921,14 @@ async function checkExternalPkgs(context, baseDir, opts, pkgs) {
492931
492921
  }
492932
492922
  }
492933
492923
  }
492934
- function maybeRenamePathExt(context, path28, ext, opts) {
492935
- if (!path28) {
492936
- return path28;
492924
+ function maybeRenamePathExt(context, filePath, fileExt, opts) {
492925
+ if (!filePath) {
492926
+ return filePath;
492937
492927
  }
492938
- const correctPath = `${stripExtension(path28, true)}${ext}`;
492939
- if (path28 !== correctPath) {
492928
+ const correctPath = `${stripExtension(filePath, true)}${fileExt}`;
492929
+ if (filePath !== correctPath) {
492940
492930
  try {
492941
- renameFile(context, path28, correctPath);
492931
+ renameFile(context, filePath, correctPath);
492942
492932
  } catch (e7) {
492943
492933
  if (!(opts == null ? void 0 : opts.continueOnFailure)) {
492944
492934
  throw e7;
@@ -492976,10 +492966,6 @@ function fixFileExtension(context) {
492976
492966
  }
492977
492967
  async function syncProject(context, opts, projectIdsAndTokens, projectId, branchName, componentIds, projectVersion, dependencies, summary, indirect, externalNpmPackages, externalCssImports, metadataDefaults) {
492978
492968
  var _a8, _b2, _c3;
492979
- const existingProject = context.config.projects.find(
492980
- (p5) => p5.projectId === projectId
492981
- );
492982
- const existingCompScheme = ((existingProject == null ? void 0 : existingProject.components) || []).map((c5) => [c5.id, c5.scheme]);
492983
492969
  const projectApiToken = ensure(
492984
492970
  (_a8 = projectIdsAndTokens.find((p5) => p5.projectId === projectId)) == null ? void 0 : _a8.projectApiToken,
492985
492971
  `Could not find the API token for project ${projectId} in list: ${JSON.stringify(
@@ -493690,7 +493676,7 @@ import_yargs.default.usage("Usage: $0 <command> [options]").option("auth", {
493690
493676
  ).command(
493691
493677
  "info",
493692
493678
  "Fetches metadata for projects",
493693
- (yags) => yags.option("host", {
493679
+ (yargs2) => yargs2.option("host", {
493694
493680
  describe: "Plasmic host to use",
493695
493681
  type: "string",
493696
493682
  default: "https://studio.plasmic.app"
package/dist/lib.js CHANGED
@@ -483497,7 +483497,7 @@ async function formatAsLocal(content, filePath, baseDir, defaultOpts) {
483497
483497
  async function nodeToFormattedCode(n26, baseDir, unformatted, commentsToRemove) {
483498
483498
  const c5 = (0, import_generator.default)(n26, {
483499
483499
  retainLines: true,
483500
- shouldPrintComment: (c7) => !commentsToRemove || !commentsToRemove.has(c7)
483500
+ shouldPrintComment: (comment) => !commentsToRemove || !commentsToRemove.has(comment)
483501
483501
  }).code;
483502
483502
  return unformatted ? c5 : await formatAsLocal(c5, "/tmp/x.tsx", baseDir, {
483503
483503
  arrowParens: "avoid"
@@ -483565,6 +483565,7 @@ function tryParsePlasmicImportSpec(node) {
483565
483565
  return void 0;
483566
483566
  }
483567
483567
  const m5 = c5.value.match(
483568
+ // eslint-disable-next-line no-misleading-character-class
483568
483569
  new RegExp(
483569
483570
  [
483570
483571
  "plasmic-import:\\s+([",
@@ -483627,7 +483628,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483627
483628
  ensureImportSpecifierWithAlias(stmt, exportName, compConfig.name);
483628
483629
  } else {
483629
483630
  }
483630
- const realPath = makeImportPath(context, fromPath, modulePath, true);
483631
+ const realPath = makeImportPath(context, fromPath, modulePath);
483631
483632
  stmt.source.value = realPath;
483632
483633
  } else if (type === "render") {
483633
483634
  const compConfig = fixImportContext.components[uuid];
@@ -483637,8 +483638,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483637
483638
  const realPath = makeImportPath(
483638
483639
  context,
483639
483640
  fromPath,
483640
- compConfig.renderModuleFilePath,
483641
- true
483641
+ compConfig.renderModuleFilePath
483642
483642
  );
483643
483643
  stmt.source.value = realPath;
483644
483644
  } else if (type === "css") {
@@ -483649,8 +483649,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483649
483649
  const realPath = makeImportPath(
483650
483650
  context,
483651
483651
  fromPath,
483652
- compConfig.cssFilePath,
483653
- false
483652
+ compConfig.cssFilePath
483654
483653
  );
483655
483654
  stmt.source.value = realPath;
483656
483655
  } else if (type === "globalVariant") {
@@ -483661,8 +483660,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483661
483660
  const realPath = makeImportPath(
483662
483661
  context,
483663
483662
  fromPath,
483664
- variantConfig.contextFilePath,
483665
- true
483663
+ variantConfig.contextFilePath
483666
483664
  );
483667
483665
  stmt.source.value = realPath;
483668
483666
  } else if (type === "icon") {
@@ -483673,8 +483671,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483673
483671
  const realPath = makeImportPath(
483674
483672
  context,
483675
483673
  fromPath,
483676
- iconConfig.moduleFilePath,
483677
- true
483674
+ iconConfig.moduleFilePath
483678
483675
  );
483679
483676
  stmt.source.value = realPath;
483680
483677
  } else if (type === "picture") {
@@ -483682,12 +483679,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483682
483679
  if (!imageConfig) {
483683
483680
  throwMissingReference(context, "image", uuid, fromPath);
483684
483681
  }
483685
- const realPath = makeImportPath(
483686
- context,
483687
- fromPath,
483688
- imageConfig.filePath,
483689
- false
483690
- );
483682
+ const realPath = makeImportPath(context, fromPath, imageConfig.filePath);
483691
483683
  stmt.source.value = realPath;
483692
483684
  } else if (type === "projectcss") {
483693
483685
  const projectConfig = fixImportContext.projects[uuid];
@@ -483697,16 +483689,14 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483697
483689
  const realPath = makeImportPath(
483698
483690
  context,
483699
483691
  fromPath,
483700
- projectConfig.cssFilePath,
483701
- false
483692
+ projectConfig.cssFilePath
483702
483693
  );
483703
483694
  stmt.source.value = realPath;
483704
483695
  } else if (type === "defaultcss") {
483705
483696
  const realPath = makeImportPath(
483706
483697
  context,
483707
483698
  fromPath,
483708
- fixImportContext.config.style.defaultStyleCssFilePath,
483709
- false
483699
+ fixImportContext.config.style.defaultStyleCssFilePath
483710
483700
  );
483711
483701
  stmt.source.value = realPath;
483712
483702
  } else if (type === "codeComponent") {
@@ -483719,7 +483709,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483719
483709
  if (meta.componentImportPath[0] === ".") {
483720
483710
  const toPath2 = import_upath2.default.join(context.rootDir, meta.componentImportPath);
483721
483711
  assert6(import_upath2.default.isAbsolute(toPath2));
483722
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
483712
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
483723
483713
  stmt.source.value = realPath;
483724
483714
  } else {
483725
483715
  stmt.source.value = meta.componentImportPath;
@@ -483734,7 +483724,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483734
483724
  if (meta.helper.importPath[0] === ".") {
483735
483725
  const toPath2 = import_upath2.default.join(context.rootDir, meta.helper.importPath);
483736
483726
  assert6(import_upath2.default.isAbsolute(toPath2));
483737
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
483727
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
483738
483728
  stmt.source.value = realPath;
483739
483729
  } else {
483740
483730
  stmt.source.value = meta.helper.importPath;
@@ -483747,8 +483737,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483747
483737
  const realPath = makeImportPath(
483748
483738
  context,
483749
483739
  fromPath,
483750
- projectConfig.globalContextsFilePath,
483751
- true
483740
+ projectConfig.globalContextsFilePath
483752
483741
  );
483753
483742
  stmt.source.value = realPath;
483754
483743
  } else if (type === "customFunction") {
@@ -483761,7 +483750,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483761
483750
  if (meta.importPath[0] === ".") {
483762
483751
  const toPath2 = import_upath2.default.join(context.rootDir, meta.importPath);
483763
483752
  assert6(import_upath2.default.isAbsolute(toPath2));
483764
- const realPath = makeImportPath(context, fromPath, toPath2, true, true);
483753
+ const realPath = makeImportPath(context, fromPath, toPath2, true);
483765
483754
  stmt.source.value = realPath;
483766
483755
  } else {
483767
483756
  stmt.source.value = meta.importPath;
@@ -483774,8 +483763,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483774
483763
  const realPath = makeImportPath(
483775
483764
  context,
483776
483765
  fromPath,
483777
- projectConfig.splitsProviderFilePath,
483778
- true
483766
+ projectConfig.splitsProviderFilePath
483779
483767
  );
483780
483768
  stmt.source.value = realPath;
483781
483769
  } else if (type === "styleTokensProvider") {
@@ -483786,8 +483774,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483786
483774
  const realPath = makeImportPath(
483787
483775
  context,
483788
483776
  fromPath,
483789
- projectConfig.styleTokensProviderFilePath,
483790
- true
483777
+ projectConfig.styleTokensProviderFilePath
483791
483778
  );
483792
483779
  stmt.source.value = realPath;
483793
483780
  } else if (type === "projectModule") {
@@ -483798,8 +483785,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483798
483785
  const realPath = makeImportPath(
483799
483786
  context,
483800
483787
  fromPath,
483801
- projectConfig.projectModuleFilePath,
483802
- true
483788
+ projectConfig.projectModuleFilePath
483803
483789
  );
483804
483790
  stmt.source.value = realPath;
483805
483791
  } else if (type === "rscClient") {
@@ -483813,12 +483799,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483813
483799
  `Encountered Plasmic component "${uuid}" that is missing a rscClientModulePath.`
483814
483800
  );
483815
483801
  }
483816
- stmt.source.value = makeImportPath(
483817
- context,
483818
- fromPath,
483819
- clientModulePath,
483820
- true
483821
- );
483802
+ stmt.source.value = makeImportPath(context, fromPath, clientModulePath);
483822
483803
  } else if (type === "rscServer") {
483823
483804
  const compConfig = fixImportContext.components[uuid];
483824
483805
  if (!compConfig) {
@@ -483833,12 +483814,7 @@ async function replaceImports(context, code, fromPath, fixImportContext, removeI
483833
483814
  logger.info(
483834
483815
  `Fixing "rscServer" with "${serverModulePath}" and from "${fromPath}"`
483835
483816
  );
483836
- stmt.source.value = makeImportPath(
483837
- context,
483838
- fromPath,
483839
- serverModulePath,
483840
- true
483841
- );
483817
+ stmt.source.value = makeImportPath(context, fromPath, serverModulePath);
483842
483818
  }
483843
483819
  });
483844
483820
  if (!changed) {
@@ -483857,8 +483833,17 @@ function throwMissingReference(context, itemType, uuid, fromPath) {
483857
483833
  `Encountered Plasmic ${itemType} "${uuid}" in ${fromPath} that are being used but have not been synced. ${recFix}`
483858
483834
  );
483859
483835
  }
483860
- function makeImportPath(context, fromPath, toPath2, stripExt, forceRelative = false) {
483836
+ function makeImportPath(context, fromPath, toPath2, forceRelative = false) {
483861
483837
  let result = toPath2;
483838
+ const stripExt = context.config.preserveJsImportExtensions ? (
483839
+ // Do not strip any extensions if the user has explicitly requested to preserve them
483840
+ false
483841
+ ) : (
483842
+ // Strip extensions only for JavaScript/TypeScript modules
483843
+ [".ts", ".tsx", ".js", ".jsx"].includes(
483844
+ import_upath2.default.extname(toPath2).toLowerCase()
483845
+ )
483846
+ );
483862
483847
  if (forceRelative || isLocalModulePath(toPath2)) {
483863
483848
  result = import_upath2.default.relative(
483864
483849
  makeFilePath(context, import_upath2.default.dirname(fromPath)),
@@ -484106,7 +484091,7 @@ var tsxToJsx = (code) => {
484106
484091
  str = str.replace(usageMagic, "");
484107
484092
  return str;
484108
484093
  }
484109
- let result = ts7.transpileModule(prepForTranspile(code), {
484094
+ const result = ts7.transpileModule(prepForTranspile(code), {
484110
484095
  compilerOptions: CompilerOptions.getOpts()
484111
484096
  });
484112
484097
  return fixPostTranspile(result.outputText);
@@ -484130,10 +484115,10 @@ async function formatScript(code, baseDir) {
484130
484115
  newLineMarker = newLineMarker + "_REALLY";
484131
484116
  }
484132
484117
  (0, import_traverse.default)(file, {
484133
- Statement: function(path28) {
484134
- if (file.program.body.includes(path28.node) && path28.node.type !== "ImportDeclaration") {
484135
- path28.insertBefore(babel.types.stringLiteral(newLineMarker));
484136
- path28.skip();
484118
+ Statement: function(filePath) {
484119
+ if (file.program.body.includes(filePath.node) && filePath.node.type !== "ImportDeclaration") {
484120
+ filePath.insertBefore(babel.types.stringLiteral(newLineMarker));
484121
+ filePath.skip();
484137
484122
  }
484138
484123
  }
484139
484124
  });
@@ -484150,8 +484135,9 @@ async function formatScript(code, baseDir) {
484150
484135
  }
484151
484136
  async function fixGlobalContextImportStatements(context, fixImportContext, baseDir) {
484152
484137
  for (const project of context.config.projects) {
484153
- if (!project.globalContextsFilePath)
484138
+ if (!project.globalContextsFilePath) {
484154
484139
  continue;
484140
+ }
484155
484141
  const resourcePath = getGlobalContextsResourcePath(context, project);
484156
484142
  let prevContent;
484157
484143
  try {
@@ -484182,8 +484168,9 @@ async function fixGlobalContextImportStatements(context, fixImportContext, baseD
484182
484168
  }
484183
484169
  async function fixImportStatements(context, fixImportContext, baseDir, configKey, getResourcePath) {
484184
484170
  for (const project of context.config.projects) {
484185
- if (!project[configKey])
484171
+ if (!project[configKey]) {
484186
484172
  continue;
484173
+ }
484187
484174
  const resourcePath = getResourcePath(context, project);
484188
484175
  let prevContent;
484189
484176
  try {
@@ -484892,7 +484879,8 @@ var DEFAULT_CONFIG = {
484892
484879
  globalVariants: {
484893
484880
  variantGroups: []
484894
484881
  },
484895
- wrapPagesWithGlobalContexts: true
484882
+ wrapPagesWithGlobalContexts: true,
484883
+ preserveJsImportExtensions: false
484896
484884
  };
484897
484885
  var DEFAULT_PUBLIC_FILES_CONFIG = {
484898
484886
  scheme: "public-files",
@@ -484963,7 +484951,7 @@ async function updateConfig(context, newConfig, baseDir) {
484963
484951
  function getOrAddProjectConfig(context, projectId, base) {
484964
484952
  let project = context.config.projects.find((p5) => p5.projectId === projectId);
484965
484953
  if (!project) {
484966
- project = !!base ? import_lodash9.default.cloneDeep(base) : {
484954
+ project = base ? import_lodash9.default.cloneDeep(base) : {
484967
484955
  projectId,
484968
484956
  projectName: "",
484969
484957
  version: "latest",
@@ -484984,7 +484972,7 @@ function getOrAddProjectConfig(context, projectId, base) {
484984
484972
  function getOrAddProjectLock(context, projectId, branchName, base) {
484985
484973
  let project = context.lock.projects.find((p5) => p5.projectId === projectId);
484986
484974
  if (!project) {
484987
- project = !!base ? import_lodash9.default.cloneDeep(base) : {
484975
+ project = base ? import_lodash9.default.cloneDeep(base) : {
484988
484976
  projectId,
484989
484977
  branchName,
484990
484978
  version: "",
@@ -487666,8 +487654,9 @@ async function ensureRequiredPackages(context, baseDir, yes) {
487666
487654
  }
487667
487655
  }
487668
487656
  async function sync(opts, metadataDefaults) {
487669
- if (!opts.baseDir)
487657
+ if (!opts.baseDir) {
487670
487658
  opts.baseDir = process.cwd();
487659
+ }
487671
487660
  const baseDir = opts.baseDir;
487672
487661
  let context = await getContext(opts, { enableSkipAuth: true });
487673
487662
  if (opts.skipFormatting) {
@@ -487867,14 +487856,14 @@ async function checkExternalPkgs(context, baseDir, opts, pkgs) {
487867
487856
  }
487868
487857
  }
487869
487858
  }
487870
- function maybeRenamePathExt(context, path28, ext, opts) {
487871
- if (!path28) {
487872
- return path28;
487859
+ function maybeRenamePathExt(context, filePath, fileExt, opts) {
487860
+ if (!filePath) {
487861
+ return filePath;
487873
487862
  }
487874
- const correctPath = `${stripExtension(path28, true)}${ext}`;
487875
- if (path28 !== correctPath) {
487863
+ const correctPath = `${stripExtension(filePath, true)}${fileExt}`;
487864
+ if (filePath !== correctPath) {
487876
487865
  try {
487877
- renameFile(context, path28, correctPath);
487866
+ renameFile(context, filePath, correctPath);
487878
487867
  } catch (e7) {
487879
487868
  if (!(opts == null ? void 0 : opts.continueOnFailure)) {
487880
487869
  throw e7;
@@ -487912,10 +487901,6 @@ function fixFileExtension(context) {
487912
487901
  }
487913
487902
  async function syncProject(context, opts, projectIdsAndTokens, projectId, branchName, componentIds, projectVersion, dependencies, summary, indirect, externalNpmPackages, externalCssImports, metadataDefaults) {
487914
487903
  var _a8, _b2, _c3;
487915
- const existingProject = context.config.projects.find(
487916
- (p5) => p5.projectId === projectId
487917
- );
487918
- const existingCompScheme = ((existingProject == null ? void 0 : existingProject.components) || []).map((c5) => [c5.id, c5.scheme]);
487919
487904
  const projectApiToken = ensure(
487920
487905
  (_a8 = projectIdsAndTokens.find((p5) => p5.projectId === projectId)) == null ? void 0 : _a8.projectApiToken,
487921
487906
  `Could not find the API token for project ${projectId} in list: ${JSON.stringify(
@@ -488513,6 +488498,7 @@ async function exportProjectsCli(opts) {
488513
488498
  platform: opts.platform || "react",
488514
488499
  srcDir: "./",
488515
488500
  defaultPlasmicDir: "./",
488501
+ preserveJsImportExtensions: false,
488516
488502
  code: {
488517
488503
  lang: opts.codeLang || "ts",
488518
488504
  scheme: "blackbox",
@@ -590,6 +590,10 @@
590
590
  },
591
591
  "type": "array"
592
592
  },
593
+ "preserveJsImportExtensions": {
594
+ "description": "Whether to preserve js / ts / jsx / tsx file extensions in import statements",
595
+ "type": "boolean"
596
+ },
593
597
  "projects": {
594
598
  "description": "Metadata for each project that has been synced",
595
599
  "items": {
@@ -630,6 +634,7 @@
630
634
  "globalVariants",
631
635
  "images",
632
636
  "platform",
637
+ "preserveJsImportExtensions",
633
638
  "projects",
634
639
  "srcDir",
635
640
  "style",
@@ -55,6 +55,8 @@ export interface PlasmicConfig {
55
55
  projects: ProjectConfig[];
56
56
  /** Wether we should wrap the pages with the project global contexts or not */
57
57
  wrapPagesWithGlobalContexts: boolean;
58
+ /** Whether to preserve js / ts / jsx / tsx file extensions in import statements */
59
+ preserveJsImportExtensions: boolean;
58
60
  /** The version of cli when this file was written */
59
61
  cliVersion?: string;
60
62
  /** Configuration for localization */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasmicapp/cli",
3
- "version": "0.1.345",
3
+ "version": "0.1.346",
4
4
  "description": "plasmic cli for syncing local code with Plasmic designs",
5
5
  "engines": {
6
6
  "node": ">=12"
@@ -82,5 +82,5 @@
82
82
  "wrap-ansi": "^7.0.0",
83
83
  "yargs": "^15.4.1"
84
84
  },
85
- "gitHead": "0102f49e64d075420884fdd1679716cd9e1da77b"
85
+ "gitHead": "2495d0e2aac1b54715640be6c5c3eea5a49a3c69"
86
86
  }
@@ -170,6 +170,7 @@ export async function exportProjectsCli(opts: ExportArgs): Promise<void> {
170
170
  platform: opts.platform || "react",
171
171
  srcDir: "./",
172
172
  defaultPlasmicDir: "./",
173
+ preserveJsImportExtensions: false,
173
174
  code: {
174
175
  lang: opts.codeLang || "ts",
175
176
  scheme: "blackbox",
@@ -181,7 +181,9 @@ export async function sync(
181
181
  // Initially allow for a missing auth. Only require an auth once we need to fetch new or updated API tokens for any
182
182
  // projects.
183
183
 
184
- if (!opts.baseDir) opts.baseDir = process.cwd();
184
+ if (!opts.baseDir) {
185
+ opts.baseDir = process.cwd();
186
+ }
185
187
  const baseDir = opts.baseDir;
186
188
  let context = await getContext(opts, { enableSkipAuth: true });
187
189
 
@@ -456,19 +458,19 @@ async function checkExternalPkgs(
456
458
 
457
459
  function maybeRenamePathExt(
458
460
  context: PlasmicContext,
459
- path: string,
460
- ext: string,
461
+ filePath: string,
462
+ fileExt: string,
461
463
  opts?: {
462
464
  continueOnFailure?: boolean;
463
465
  }
464
466
  ) {
465
- if (!path) {
466
- return path;
467
+ if (!filePath) {
468
+ return filePath;
467
469
  }
468
- const correctPath = `${stripExtension(path, true)}${ext}`;
469
- if (path !== correctPath) {
470
+ const correctPath = `${stripExtension(filePath, true)}${fileExt}`;
471
+ if (filePath !== correctPath) {
470
472
  try {
471
- renameFile(context, path, correctPath);
473
+ renameFile(context, filePath, correctPath);
472
474
  } catch (e) {
473
475
  if (!opts?.continueOnFailure) {
474
476
  throw e;
@@ -522,13 +524,6 @@ async function syncProject(
522
524
  externalCssImports: Set<string>,
523
525
  metadataDefaults?: Metadata
524
526
  ): Promise<void> {
525
- const existingProject = context.config.projects.find(
526
- (p) => p.projectId === projectId
527
- );
528
- const existingCompScheme: Array<[string, "blackbox" | "direct"]> = (
529
- existingProject?.components || []
530
- ).map((c) => [c.id, c.scheme]);
531
-
532
527
  const projectApiToken = ensure(
533
528
  projectIdsAndTokens.find((p) => p.projectId === projectId)?.projectApiToken,
534
529
  `Could not find the API token for project ${projectId} in list: ${JSON.stringify(
package/src/index.ts CHANGED
@@ -2,17 +2,17 @@
2
2
  import yargs from "yargs";
3
3
  import * as auth from "./actions/auth";
4
4
  import { ExportArgs, exportProjectsCli } from "./actions/export";
5
- import { fixImports, FixImportsArgs } from "./actions/fix-imports";
5
+ import { FixImportsArgs, fixImports } from "./actions/fix-imports";
6
6
  import { InfoArgs, printProjectInfo } from "./actions/info";
7
- import { getYargsOption, InitArgs, initPlasmic } from "./actions/init";
7
+ import { InitArgs, getYargsOption, initPlasmic } from "./actions/init";
8
8
  import {
9
+ LocalizationStringsArgs,
9
10
  getLocalizationYargs,
10
11
  localizationStrings,
11
- LocalizationStringsArgs,
12
12
  } from "./actions/localization-strings";
13
13
  import * as projectToken from "./actions/project-token";
14
- import { showProjectStatus, StatusArgs } from "./actions/status";
15
- import { sync, SyncArgs } from "./actions/sync";
14
+ import { StatusArgs, showProjectStatus } from "./actions/status";
15
+ import { SyncArgs, sync } from "./actions/sync";
16
16
  import { UploadBundleArgs, uploadJsBundle } from "./actions/upload-bundle";
17
17
  import { WatchArgs, watchProjects } from "./actions/watch";
18
18
  import { handleError } from "./utils/error";
@@ -110,8 +110,8 @@ yargs
110
110
  .command<StatusArgs>(
111
111
  "status",
112
112
  "Shows the status of local Plasmic projects.",
113
- (yargs) =>
114
- yargs.option("json", {
113
+ (yargs2) =>
114
+ yargs2.option("json", {
115
115
  describe: "Output status in JSON format",
116
116
  type: "boolean",
117
117
  default: false,
@@ -160,8 +160,8 @@ yargs
160
160
  .command<InfoArgs>(
161
161
  "info",
162
162
  "Fetches metadata for projects",
163
- (yags) =>
164
- yags
163
+ (yargs2) =>
164
+ yargs2
165
165
  .option("host", {
166
166
  describe: "Plasmic host to use",
167
167
  type: "string",
@@ -185,8 +185,8 @@ yargs
185
185
  .command<UploadBundleArgs>(
186
186
  "upload-bundle",
187
187
  false,
188
- (yargs) =>
189
- yargs
188
+ (yargs2) =>
189
+ yargs2
190
190
  .option("project", {
191
191
  alias: "p",
192
192
  describe: "ID of Plasmic project to upload the bundle to.",
@@ -246,8 +246,8 @@ yargs
246
246
  .command<projectToken.ProjectTokenArgs>(
247
247
  "project-token <projectId>",
248
248
  "Get projectApiToken for a given project",
249
- (yargs) =>
250
- yargs
249
+ (yargs2) =>
250
+ yargs2
251
251
  .positional("projectId", {
252
252
  describe: "projectId",
253
253
  type: "string",
@@ -262,8 +262,8 @@ yargs
262
262
  .command<LocalizationStringsArgs>(
263
263
  "localization-strings",
264
264
  "Generate localization strings",
265
- (yargs) =>
266
- yargs
265
+ (yargs2) =>
266
+ yargs2
267
267
  .option("projects", {
268
268
  alias: "p",
269
269
  describe:
@@ -310,8 +310,8 @@ yargs
310
310
  .command<ExportArgs>(
311
311
  "export",
312
312
  false,
313
- (yargs) =>
314
- yargs
313
+ (yargs2) =>
314
+ yargs2
315
315
  .option("projects", {
316
316
  alias: "p",
317
317
  describe: "ID of project to export from",
@@ -36,6 +36,7 @@ export const defaultPlasmicJson: PlasmicConfig = {
36
36
  variantGroups: [],
37
37
  },
38
38
  wrapPagesWithGlobalContexts: true,
39
+ preserveJsImportExtensions: false,
39
40
  cliVersion: "0.1.44",
40
41
  };
41
42
  export function standardTestSetup(includeDep = true) {
@@ -78,7 +78,8 @@ async function nodeToFormattedCode(
78
78
  ): Promise<string> {
79
79
  const c = generate(n, {
80
80
  retainLines: true,
81
- shouldPrintComment: (c) => !commentsToRemove || !commentsToRemove.has(c),
81
+ shouldPrintComment: (comment) =>
82
+ !commentsToRemove || !commentsToRemove.has(comment),
82
83
  }).code;
83
84
  return unformatted
84
85
  ? c
@@ -205,6 +206,7 @@ function tryParsePlasmicImportSpec(node: ImportDeclaration) {
205
206
  return undefined;
206
207
  }
207
208
  const m = c.value.match(
209
+ // eslint-disable-next-line no-misleading-character-class
208
210
  new RegExp(
209
211
  [
210
212
  "plasmic-import:\\s+([",
@@ -287,7 +289,7 @@ export async function replaceImports(
287
289
  // to name collisions.
288
290
  // ensureImportDefaultSpecifier(stmt, compConfig.name);
289
291
  }
290
- const realPath = makeImportPath(context, fromPath, modulePath, true);
292
+ const realPath = makeImportPath(context, fromPath, modulePath);
291
293
  stmt.source.value = realPath;
292
294
  } else if (type === "render") {
293
295
  // import of the PP blackbox
@@ -298,8 +300,7 @@ export async function replaceImports(
298
300
  const realPath = makeImportPath(
299
301
  context,
300
302
  fromPath,
301
- compConfig.renderModuleFilePath,
302
- true
303
+ compConfig.renderModuleFilePath
303
304
  );
304
305
  stmt.source.value = realPath;
305
306
  } else if (type === "css") {
@@ -311,8 +312,7 @@ export async function replaceImports(
311
312
  const realPath = makeImportPath(
312
313
  context,
313
314
  fromPath,
314
- compConfig.cssFilePath,
315
- false
315
+ compConfig.cssFilePath
316
316
  );
317
317
  stmt.source.value = realPath;
318
318
  } else if (type === "globalVariant") {
@@ -324,8 +324,7 @@ export async function replaceImports(
324
324
  const realPath = makeImportPath(
325
325
  context,
326
326
  fromPath,
327
- variantConfig.contextFilePath,
328
- true
327
+ variantConfig.contextFilePath
329
328
  );
330
329
  stmt.source.value = realPath;
331
330
  } else if (type === "icon") {
@@ -337,8 +336,7 @@ export async function replaceImports(
337
336
  const realPath = makeImportPath(
338
337
  context,
339
338
  fromPath,
340
- iconConfig.moduleFilePath,
341
- true
339
+ iconConfig.moduleFilePath
342
340
  );
343
341
  stmt.source.value = realPath;
344
342
  } else if (type === "picture") {
@@ -346,12 +344,7 @@ export async function replaceImports(
346
344
  if (!imageConfig) {
347
345
  throwMissingReference(context, "image", uuid, fromPath);
348
346
  }
349
- const realPath = makeImportPath(
350
- context,
351
- fromPath,
352
- imageConfig.filePath,
353
- false
354
- );
347
+ const realPath = makeImportPath(context, fromPath, imageConfig.filePath);
355
348
  stmt.source.value = realPath;
356
349
  } else if (type === "projectcss") {
357
350
  const projectConfig = fixImportContext.projects[uuid];
@@ -361,16 +354,14 @@ export async function replaceImports(
361
354
  const realPath = makeImportPath(
362
355
  context,
363
356
  fromPath,
364
- projectConfig.cssFilePath,
365
- false
357
+ projectConfig.cssFilePath
366
358
  );
367
359
  stmt.source.value = realPath;
368
360
  } else if (type === "defaultcss") {
369
361
  const realPath = makeImportPath(
370
362
  context,
371
363
  fromPath,
372
- fixImportContext.config.style.defaultStyleCssFilePath,
373
- false
364
+ fixImportContext.config.style.defaultStyleCssFilePath
374
365
  );
375
366
  stmt.source.value = realPath;
376
367
  } else if (type === "codeComponent") {
@@ -384,7 +375,7 @@ export async function replaceImports(
384
375
  // Relative path from the project root
385
376
  const toPath = path.join(context.rootDir, meta.componentImportPath);
386
377
  assert(path.isAbsolute(toPath));
387
- const realPath = makeImportPath(context, fromPath, toPath, true, true);
378
+ const realPath = makeImportPath(context, fromPath, toPath, true);
388
379
  stmt.source.value = realPath;
389
380
  } else {
390
381
  // npm package
@@ -401,7 +392,7 @@ export async function replaceImports(
401
392
  // Relative path from the project root
402
393
  const toPath = path.join(context.rootDir, meta.helper.importPath);
403
394
  assert(path.isAbsolute(toPath));
404
- const realPath = makeImportPath(context, fromPath, toPath, true, true);
395
+ const realPath = makeImportPath(context, fromPath, toPath, true);
405
396
  stmt.source.value = realPath;
406
397
  } else {
407
398
  // npm package
@@ -415,8 +406,7 @@ export async function replaceImports(
415
406
  const realPath = makeImportPath(
416
407
  context,
417
408
  fromPath,
418
- projectConfig.globalContextsFilePath,
419
- true
409
+ projectConfig.globalContextsFilePath
420
410
  );
421
411
  stmt.source.value = realPath;
422
412
  } else if (type === "customFunction") {
@@ -430,7 +420,7 @@ export async function replaceImports(
430
420
  // Relative path from the project root
431
421
  const toPath = path.join(context.rootDir, meta.importPath);
432
422
  assert(path.isAbsolute(toPath));
433
- const realPath = makeImportPath(context, fromPath, toPath, true, true);
423
+ const realPath = makeImportPath(context, fromPath, toPath, true);
434
424
  stmt.source.value = realPath;
435
425
  } else {
436
426
  // npm package
@@ -444,8 +434,7 @@ export async function replaceImports(
444
434
  const realPath = makeImportPath(
445
435
  context,
446
436
  fromPath,
447
- projectConfig.splitsProviderFilePath,
448
- true
437
+ projectConfig.splitsProviderFilePath
449
438
  );
450
439
  stmt.source.value = realPath;
451
440
  } else if (type === "styleTokensProvider") {
@@ -456,8 +445,7 @@ export async function replaceImports(
456
445
  const realPath = makeImportPath(
457
446
  context,
458
447
  fromPath,
459
- projectConfig.styleTokensProviderFilePath,
460
- true
448
+ projectConfig.styleTokensProviderFilePath
461
449
  );
462
450
  stmt.source.value = realPath;
463
451
  } else if (type === "projectModule") {
@@ -468,8 +456,7 @@ export async function replaceImports(
468
456
  const realPath = makeImportPath(
469
457
  context,
470
458
  fromPath,
471
- projectConfig.projectModuleFilePath,
472
- true
459
+ projectConfig.projectModuleFilePath
473
460
  );
474
461
  stmt.source.value = realPath;
475
462
  } else if (type === "rscClient") {
@@ -484,12 +471,7 @@ export async function replaceImports(
484
471
  );
485
472
  }
486
473
 
487
- stmt.source.value = makeImportPath(
488
- context,
489
- fromPath,
490
- clientModulePath,
491
- true
492
- );
474
+ stmt.source.value = makeImportPath(context, fromPath, clientModulePath);
493
475
  } else if (type === "rscServer") {
494
476
  const compConfig = fixImportContext.components[uuid];
495
477
  if (!compConfig) {
@@ -506,12 +488,7 @@ export async function replaceImports(
506
488
  `Fixing "rscServer" with "${serverModulePath}" and from "${fromPath}"`
507
489
  );
508
490
 
509
- stmt.source.value = makeImportPath(
510
- context,
511
- fromPath,
512
- serverModulePath,
513
- true
514
- );
491
+ stmt.source.value = makeImportPath(context, fromPath, serverModulePath);
515
492
  }
516
493
  });
517
494
 
@@ -543,10 +520,17 @@ function makeImportPath(
543
520
  context: PlasmicContext,
544
521
  fromPath: string,
545
522
  toPath: string,
546
- stripExt: boolean,
547
523
  forceRelative = false
548
524
  ) {
549
525
  let result = toPath;
526
+ const stripExt = context.config.preserveJsImportExtensions
527
+ ? // Do not strip any extensions if the user has explicitly requested to preserve them
528
+ false
529
+ : // Strip extensions only for JavaScript/TypeScript modules
530
+ [".ts", ".tsx", ".js", ".jsx"].includes(
531
+ path.extname(toPath).toLowerCase()
532
+ );
533
+
550
534
  if (forceRelative || isLocalModulePath(toPath)) {
551
535
  result = path.relative(
552
536
  makeFilePath(context, path.dirname(fromPath)),
@@ -843,7 +827,7 @@ class CompilerOptions {
843
827
  curDir = path.join(curDir, "..");
844
828
  configPath = path.join(curDir, "tsconfig-transform.json");
845
829
  } while (!existsBuffered(configPath));
846
- const c = ts.readConfigFile(configPath, (path) => readFileText(path));
830
+ const c = ts.readConfigFile(configPath, (path2) => readFileText(path2));
847
831
  this.opts = ts.convertCompilerOptionsFromJson(
848
832
  c.config.compilerOptions,
849
833
  "."
@@ -876,7 +860,7 @@ export const tsxToJsx = (code: string) => {
876
860
  return str;
877
861
  }
878
862
 
879
- let result = ts.transpileModule(prepForTranspile(code), {
863
+ const result = ts.transpileModule(prepForTranspile(code), {
880
864
  compilerOptions: CompilerOptions.getOpts(),
881
865
  });
882
866
  return fixPostTranspile(result.outputText);
@@ -909,13 +893,13 @@ export async function formatScript(
909
893
  newLineMarker = newLineMarker + "_REALLY";
910
894
  }
911
895
  traverse(file, {
912
- Statement: function (path) {
896
+ Statement: function (filePath) {
913
897
  if (
914
- file.program.body.includes(path.node) &&
915
- path.node.type !== "ImportDeclaration"
898
+ file.program.body.includes(filePath.node) &&
899
+ filePath.node.type !== "ImportDeclaration"
916
900
  ) {
917
- path.insertBefore(babel.types.stringLiteral(newLineMarker));
918
- path.skip();
901
+ filePath.insertBefore(babel.types.stringLiteral(newLineMarker));
902
+ filePath.skip();
919
903
  }
920
904
  },
921
905
  });
@@ -938,7 +922,9 @@ async function fixGlobalContextImportStatements(
938
922
  baseDir: string
939
923
  ) {
940
924
  for (const project of context.config.projects) {
941
- if (!project.globalContextsFilePath) continue;
925
+ if (!project.globalContextsFilePath) {
926
+ continue;
927
+ }
942
928
  const resourcePath = getGlobalContextsResourcePath(context, project);
943
929
 
944
930
  let prevContent: string;
@@ -976,10 +962,12 @@ async function fixImportStatements(
976
962
  fixImportContext: FixImportContext,
977
963
  baseDir: string,
978
964
  configKey: keyof ProjectConfig,
979
- getResourcePath: (context: PlasmicContext, project: ProjectConfig) => string
965
+ getResourcePath: (ctx: PlasmicContext, project: ProjectConfig) => string
980
966
  ) {
981
967
  for (const project of context.config.projects) {
982
- if (!project[configKey]) continue;
968
+ if (!project[configKey]) {
969
+ continue;
970
+ }
983
971
 
984
972
  const resourcePath = getResourcePath(context, project);
985
973
 
@@ -86,6 +86,9 @@ export interface PlasmicConfig {
86
86
  /** Wether we should wrap the pages with the project global contexts or not */
87
87
  wrapPagesWithGlobalContexts: boolean;
88
88
 
89
+ /** Whether to preserve js / ts / jsx / tsx file extensions in import statements */
90
+ preserveJsImportExtensions: boolean;
91
+
89
92
  /** The version of cli when this file was written */
90
93
  cliVersion?: string;
91
94
 
@@ -493,6 +496,7 @@ export const DEFAULT_CONFIG: PlasmicConfig = {
493
496
  variantGroups: [],
494
497
  },
495
498
  wrapPagesWithGlobalContexts: true,
499
+ preserveJsImportExtensions: false,
496
500
  };
497
501
 
498
502
  export const DEFAULT_PUBLIC_FILES_CONFIG: ImagesConfig = {
@@ -610,7 +614,7 @@ export function getOrAddProjectConfig(
610
614
  ): ProjectConfig {
611
615
  let project = context.config.projects.find((p) => p.projectId === projectId);
612
616
  if (!project) {
613
- project = !!base
617
+ project = base
614
618
  ? L.cloneDeep(base)
615
619
  : {
616
620
  projectId,
@@ -639,7 +643,7 @@ export function getOrAddProjectLock(
639
643
  ): ProjectLock {
640
644
  let project = context.lock.projects.find((p) => p.projectId === projectId);
641
645
  if (!project) {
642
- project = !!base
646
+ project = base
643
647
  ? L.cloneDeep(base)
644
648
  : {
645
649
  projectId,