@_linked/cli 1.2.11 → 1.3.3

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.
Files changed (76) hide show
  1. package/.changeset/README.md +20 -0
  2. package/.changeset/config.json +14 -0
  3. package/.github/workflows/changeset-check.yml +44 -0
  4. package/.github/workflows/ci.yml +43 -0
  5. package/.github/workflows/publish.yml +42 -0
  6. package/CHANGELOG.md +36 -0
  7. package/README.md +97 -10
  8. package/defaults/package/package.json +4 -6
  9. package/defaults/setup-publish/changeset/README.md +20 -0
  10. package/defaults/setup-publish/changeset/config.json +14 -0
  11. package/defaults/setup-publish/dual-branch/changeset/README.md +20 -0
  12. package/defaults/setup-publish/dual-branch/changeset/config.json +14 -0
  13. package/defaults/setup-publish/dual-branch/github/workflows/changeset-check.yml +43 -0
  14. package/defaults/setup-publish/dual-branch/github/workflows/ci.yml +44 -0
  15. package/defaults/setup-publish/dual-branch/github/workflows/publish.yml +122 -0
  16. package/defaults/setup-publish/github/workflows/changeset-check.yml +44 -0
  17. package/defaults/setup-publish/github/workflows/ci.yml +43 -0
  18. package/defaults/setup-publish/github/workflows/publish.yml +42 -0
  19. package/lib/cjs/cli-deprecated.js +17 -7
  20. package/lib/cjs/cli-deprecated.js.map +1 -1
  21. package/lib/cjs/cli-methods.d.ts.map +1 -1
  22. package/lib/cjs/cli-methods.js +88 -33
  23. package/lib/cjs/cli-methods.js.map +1 -1
  24. package/lib/cjs/cli.js +33 -7
  25. package/lib/cjs/cli.js.map +1 -1
  26. package/lib/cjs/commands/build-package.js +1 -2
  27. package/lib/cjs/commands/build-package.js.map +1 -1
  28. package/lib/cjs/commands/safe-yarn.js +1 -2
  29. package/lib/cjs/commands/safe-yarn.js.map +1 -1
  30. package/lib/cjs/commands/setup-publish.d.ts.map +1 -0
  31. package/lib/cjs/commands/setup-publish.js +357 -0
  32. package/lib/cjs/commands/setup-publish.js.map +1 -0
  33. package/lib/cjs/config-webpack-app.d.ts.map +1 -1
  34. package/lib/cjs/config-webpack-app.js +17 -7
  35. package/lib/cjs/config-webpack-app.js.map +1 -1
  36. package/lib/cjs/config-webpack.js +18 -9
  37. package/lib/cjs/config-webpack.js.map +1 -1
  38. package/lib/cjs/defineConfig.js +1 -2
  39. package/lib/cjs/defineConfig.js.map +1 -1
  40. package/lib/cjs/index.d.ts.map +1 -1
  41. package/lib/cjs/index.js +7 -3
  42. package/lib/cjs/index.js.map +1 -1
  43. package/lib/cjs/loaders/css-loader.mjs +5 -12
  44. package/lib/cjs/loaders/css-loader.mjs.map +1 -1
  45. package/lib/cjs/package.json +4 -5
  46. package/lib/cjs/plugins/check-imports.js +1 -1
  47. package/lib/cjs/plugins/check-imports.js.map +1 -1
  48. package/lib/cjs/plugins/declaration-plugin.d.ts.map +1 -1
  49. package/lib/cjs/plugins/declaration-plugin.js +17 -7
  50. package/lib/cjs/plugins/declaration-plugin.js.map +1 -1
  51. package/lib/cjs/plugins/externalise-modules.d.ts.map +1 -1
  52. package/lib/cjs/tailwind.config.js +2 -2
  53. package/lib/cjs/tailwind.config.js.map +1 -1
  54. package/lib/cjs/utils.d.ts.map +1 -1
  55. package/lib/cjs/utils.js +30 -20
  56. package/lib/cjs/utils.js.map +1 -1
  57. package/lib/esm/cli-methods.d.ts.map +1 -1
  58. package/lib/esm/cli-methods.js +76 -31
  59. package/lib/esm/cli-methods.js.map +1 -1
  60. package/lib/esm/cli.js +16 -0
  61. package/lib/esm/cli.js.map +1 -1
  62. package/lib/esm/commands/setup-publish.d.ts.map +1 -0
  63. package/lib/esm/commands/setup-publish.js +347 -0
  64. package/lib/esm/commands/setup-publish.js.map +1 -0
  65. package/lib/esm/config-webpack-app.d.ts.map +1 -1
  66. package/lib/esm/config-webpack-app.js +7 -7
  67. package/lib/esm/index.d.ts.map +1 -1
  68. package/lib/esm/index.js +5 -1
  69. package/lib/esm/index.js.map +1 -1
  70. package/lib/esm/package.json +4 -5
  71. package/lib/esm/plugins/declaration-plugin.d.ts.map +1 -1
  72. package/lib/esm/plugins/externalise-modules.d.ts.map +1 -1
  73. package/lib/esm/tailwind.config.js +1 -1
  74. package/lib/esm/tailwind.config.js.map +1 -1
  75. package/lib/esm/utils.d.ts.map +1 -1
  76. package/package.json +4 -5
@@ -21,7 +21,7 @@ import { statSync } from 'fs';
21
21
  import { LinkedFileStorage } from '@_linked/core/utils/LinkedFileStorage';
22
22
  // import pkg from 'lincd/utils/LinkedFileStorage';
23
23
  // const { LinkedFileStorage } = pkg;
24
- // const config = require('lincd-server/site.webpack.config');
24
+ // const config = require('@_linked/server/site.webpack.config');
25
25
  import { glob } from 'glob';
26
26
  import webpack from 'webpack';
27
27
  import ora from 'ora';
@@ -216,7 +216,7 @@ export function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack,
216
216
  var pack = getPackageJSON(pkg.path);
217
217
  if (pack) {
218
218
  //get lincd related dependencies and get the actual package details from the package map by removing '@dacore/' from the package name
219
- let packageDependencies = Object.keys(pack.dependencies)
219
+ let packageDependencies = Object.keys(pack.dependencies || {})
220
220
  .filter((dependency) => lincdPackages.has(dependency))
221
221
  .map((dependency) => {
222
222
  return lincdPackages.has(dependency)
@@ -549,6 +549,7 @@ export function buildAll(options) {
549
549
  }
550
550
  debugInfo('Now building: ' + chalk.blue(packageGroup.map((i) => i.packageName)));
551
551
  return (pkg) => __awaiter(this, void 0, void 0, function* () {
552
+ var _a;
552
553
  let command;
553
554
  let skipping = false;
554
555
  //if we're skipping builds until a certain package
@@ -566,16 +567,26 @@ export function buildAll(options) {
566
567
  }
567
568
  //unless told otherwise, build the package
568
569
  if (!command) {
569
- command = buildPackage(null, null, path.join(process.cwd(), pkg.path), false);
570
- // command = execPromise(
571
- // 'cd ' + pkg.path + ' && yarn exec lincd build',
572
- // // (target ? ' ' + target : '') +
573
- // // (target2 ? ' ' + target2 : ''),
574
- // false,
575
- // false,
576
- // {},
577
- // false,
578
- // );
570
+ // Invoke the package's own `yarn build` script. This lets each package
571
+ // own its build pipeline — e.g. @_linked/core uses direct tsc, pure-CSS
572
+ // packages may have no-op builds, and linkedPackage: true packages
573
+ // typically call `yarn linked build` internally.
574
+ const pkgDir = path.join(process.cwd(), pkg.path);
575
+ const pkgJson = getPackageJSON(pkgDir);
576
+ const hasBuildScript = !!((_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.scripts) === null || _a === void 0 ? void 0 : _a.build);
577
+ if (!hasBuildScript) {
578
+ // No build script — skip gracefully (e.g. a pure-assets package).
579
+ command = Promise.resolve(true);
580
+ }
581
+ else {
582
+ command = execPromise('yarn build', false, false, {
583
+ cwd: pkgDir,
584
+ })
585
+ .then((res) => res === '' || typeof res === 'string')
586
+ .catch((err) => ({
587
+ error: err.stdout || err.stderr || String(err),
588
+ }));
589
+ }
579
590
  log(chalk.cyan('Building ' + pkg.packageName));
580
591
  process.stdout.write(packagesLeft + ' packages left\r');
581
592
  }
@@ -805,7 +816,7 @@ const camelCase = (str) => {
805
816
  }
806
817
  return str;
807
818
  };
808
- export const createOntology = (prefix_1, uriBase_1, ...args_2) => __awaiter(void 0, [prefix_1, uriBase_1, ...args_2], void 0, function* (prefix, uriBase, basePath = process.cwd()) {
819
+ export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void 0, [prefix_1, uriBase_1, ...args_1], void 0, function* (prefix, uriBase, basePath = process.cwd()) {
809
820
  if (!prefix) {
810
821
  console.warn('Please provide a suggested prefix as the first argument');
811
822
  return;
@@ -968,7 +979,7 @@ export const getScriptDir = () => {
968
979
  // return dirname(import.meta.url).replace('file:/','');
969
980
  // }
970
981
  };
971
- export const createShape = (name_2, ...args_3) => __awaiter(void 0, [name_2, ...args_3], void 0, function* (name, basePath = process.cwd()) {
982
+ export const createShape = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
972
983
  let sourceFolder = getSourceFolder(basePath);
973
984
  let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
974
985
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
@@ -986,7 +997,7 @@ export const createShape = (name_2, ...args_3) => __awaiter(void 0, [name_2, ...
986
997
  log(`Added an import of this file from ${chalk.magenta(indexPath)}`);
987
998
  }
988
999
  });
989
- export const createSetComponent = (name_3, ...args_4) => __awaiter(void 0, [name_3, ...args_4], void 0, function* (name, basePath = process.cwd()) {
1000
+ export const createSetComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
990
1001
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
991
1002
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
992
1003
  //copy default shape file
@@ -1000,7 +1011,7 @@ export const createSetComponent = (name_3, ...args_4) => __awaiter(void 0, [name
1000
1011
  let indexPath = addLineToIndex(`import './components/${hyphenName}.js';`, 'components');
1001
1012
  log(`Created a new set component in ${chalk.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk.magenta(indexPath)}`);
1002
1013
  });
1003
- export const createComponent = (name_4, ...args_5) => __awaiter(void 0, [name_4, ...args_5], void 0, function* (name, basePath = process.cwd()) {
1014
+ export const createComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
1004
1015
  let sourceFolder = getSourceFolder(basePath);
1005
1016
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
1006
1017
  let { hyphenName, camelCaseName, underscoreName } = setNameVariables(name);
@@ -1023,8 +1034,12 @@ export const createComponent = (name_4, ...args_5) => __awaiter(void 0, [name_4,
1023
1034
  //read the source of all ts/tsx files in the src folder
1024
1035
  //if there is an import that imports a lincd package with /src/ in it, then warn
1025
1036
  //if there is an import that imports something from outside the src folder, then warn
1026
- export const checkImports = (...args_6) => __awaiter(void 0, [...args_6], void 0, function* (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
1037
+ export const checkImports = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside the src folder
1027
1038
  invalidImports = new Map()) {
1039
+ if (!fs.existsSync(sourceFolder)) {
1040
+ // Package has no src/ folder (e.g. pure-CSS packages). Nothing to check.
1041
+ return true;
1042
+ }
1028
1043
  const dir = fs.readdirSync(sourceFolder);
1029
1044
  // Start checking each file in the source folder
1030
1045
  for (const file of dir) {
@@ -1097,8 +1112,9 @@ invalidImports = new Map()) {
1097
1112
  res += chalk.red(message + '\n');
1098
1113
  });
1099
1114
  });
1115
+ // Throw so buildStep aborts the compile pipeline — relative imports MUST
1116
+ // have .js (or .scss) extensions for native-ESM-compatible output.
1100
1117
  throw res;
1101
- // process.exit(1);
1102
1118
  }
1103
1119
  else if (depth === 0 && invalidImports.size === 0) {
1104
1120
  // console.info('All imports OK');
@@ -1129,7 +1145,7 @@ export const depCheckStaged = () => __awaiter(void 0, void 0, void 0, function*
1129
1145
  });
1130
1146
  });
1131
1147
  });
1132
- export const depCheck = (...args_7) => __awaiter(void 0, [...args_7], void 0, function* (packagePath = process.cwd()) {
1148
+ export const depCheck = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1133
1149
  // log('Checking depencies of ' + chalk.cyan(packagePath));
1134
1150
  return new Promise((resolve, reject) => {
1135
1151
  depcheck(packagePath, {}, (results) => {
@@ -1262,7 +1278,7 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
1262
1278
  lincdConfig.server.loadRoutes = () => __awaiter(void 0, void 0, void 0, function* () { return yield import(path.join(process.cwd(), 'src', 'routes.tsx')); });
1263
1279
  }
1264
1280
  //@ts-ignore
1265
- const ServerClass = (yield import('lincd-server/shapes/LincdServer'))
1281
+ const ServerClass = (yield import('@_linked/server/shapes/LincdServer'))
1266
1282
  .LincdServer;
1267
1283
  yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
1268
1284
  let server = new ServerClass(lincdConfig);
@@ -1335,7 +1351,7 @@ export const runMethod = (packageName, method, options) => __awaiter(void 0, voi
1335
1351
  });
1336
1352
  }
1337
1353
  });
1338
- export const startServer = (...args_8) => __awaiter(void 0, [...args_8], void 0, function* (initOnly = false, ServerClass = null) {
1354
+ export const startServer = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (initOnly = false, ServerClass = null) {
1339
1355
  yield ensureEnvironmentLoaded();
1340
1356
  let lincdConfig = (yield import(path.join(process.cwd(), 'lincd.config.js')))
1341
1357
  .default;
@@ -1351,7 +1367,7 @@ export const startServer = (...args_8) => __awaiter(void 0, [...args_8], void 0,
1351
1367
  // hook.hook('.module.css', scssLoadcall);
1352
1368
  if (!ServerClass) {
1353
1369
  //@ts-ignore
1354
- ServerClass = (yield import('lincd-server/shapes/LincdServer')).LincdServer;
1370
+ ServerClass = (yield import('@_linked/server/shapes/LincdServer')).LincdServer;
1355
1371
  }
1356
1372
  yield import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
1357
1373
  // Set default loadAppComponent if not provided
@@ -1695,7 +1711,7 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
1695
1711
  // })
1696
1712
  // });
1697
1713
  });
1698
- export const createPackage = (name_5, uriBase_2, ...args_9) => __awaiter(void 0, [name_5, uriBase_2, ...args_9], void 0, function* (name, uriBase, basePath = process.cwd()) {
1714
+ export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0, [name_1, uriBase_1, ...args_1], void 0, function* (name, uriBase, basePath = process.cwd()) {
1699
1715
  if (!name) {
1700
1716
  console.warn('Please provide a name as the first argument');
1701
1717
  return;
@@ -1828,7 +1844,7 @@ export const register = function (registryURL) {
1828
1844
  console.warn(chalk.red('Warning:') + ' not found: ' + process.cwd() + '/package.json');
1829
1845
  }
1830
1846
  };
1831
- export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void 0, [target_1, target2_1, ...args_10], void 0, function* (target, target2, packagePath = process.cwd(), logResults = true) {
1847
+ export const buildPackage = (target_1, target2_1, ...args_1) => __awaiter(void 0, [target_1, target2_1, ...args_1], void 0, function* (target, target2, packagePath = process.cwd(), logResults = true) {
1832
1848
  // Ensure packagePath is absolute and points to a directory containing package.json; if not, go up until we find one
1833
1849
  // First, resolve to absolute path
1834
1850
  let currentPath = path.isAbsolute(packagePath)
@@ -1847,6 +1863,21 @@ export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void
1847
1863
  }
1848
1864
  // Always use the resolved absolute path
1849
1865
  packagePath = currentPath;
1866
+ // Guard: `linked build` only makes sense for linkedPackage. Apps must use
1867
+ // `linked build-app`. Plain packages (no linked flag) have no build pipeline
1868
+ // defined here and should have their own build script.
1869
+ const pkgJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8'));
1870
+ const isPackage = pkgJson.linkedPackage === true || pkgJson.lincd === true;
1871
+ const isApp = pkgJson.linkedApp === true || pkgJson.lincdApp === true;
1872
+ if (!isPackage) {
1873
+ if (isApp) {
1874
+ console.error(chalk.red(`'${pkgJson.name || packagePath}' is a linkedApp, not a linkedPackage. Use 'linked build-app' instead of 'linked build'.`));
1875
+ }
1876
+ else {
1877
+ console.error(chalk.red(`'${pkgJson.name || packagePath}' does not have 'linkedPackage: true' in package.json. 'linked build' only builds linked packages. Add the flag or run a different build command.`));
1878
+ }
1879
+ return false;
1880
+ }
1850
1881
  let spinner;
1851
1882
  if (logResults) {
1852
1883
  //TODO: replace with listr so we can show multiple processes at once
@@ -1936,7 +1967,14 @@ export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void
1936
1967
  buildStep({
1937
1968
  name: 'Dual package support',
1938
1969
  apply: () => {
1939
- return execPromise('yarn tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
1970
+ // Skip if no tsconfig files (e.g. pure-CSS packages).
1971
+ if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json')) ||
1972
+ !fs.existsSync(path.join(packagePath, 'tsconfig-cjs.json'))) {
1973
+ return Promise.resolve(true);
1974
+ }
1975
+ // Resolve the binary from the nearest node_modules (supports both
1976
+ // per-package and workspace-root installs of tsconfig-to-dual-package).
1977
+ return execPromise('npx tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
1940
1978
  return res === '';
1941
1979
  });
1942
1980
  },
@@ -1991,7 +2029,7 @@ export const buildPackage = (target_1, target2_1, ...args_10) => __awaiter(void
1991
2029
  }
1992
2030
  return success;
1993
2031
  });
1994
- export const compilePackage = (...args_11) => __awaiter(void 0, [...args_11], void 0, function* (packagePath = process.cwd()) {
2032
+ export const compilePackage = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
1995
2033
  //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
1996
2034
  // let cjsConfig = fs.existsSync(path.join(packagePath,'tsconfig-cjs.json'));
1997
2035
  // let esmConfig = fs.existsSync(path.join(packagePath,'tsconfig-esm.json'));
@@ -2017,15 +2055,22 @@ export const compilePackage = (...args_11) => __awaiter(void 0, [...args_11], vo
2017
2055
  yield compilePackageESM(packagePath);
2018
2056
  yield compilePackageCJS(packagePath);
2019
2057
  });
2020
- export const compilePackageESM = (...args_12) => __awaiter(void 0, [...args_12], void 0, function* (packagePath = process.cwd()) {
2021
- //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
2022
- let compileCommand = `yarn exec tsc -p tsconfig-esm.json`;
2058
+ export const compilePackageESM = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
2059
+ // Skip packages without a tsconfig-esm.json (e.g. pure-CSS packages).
2060
+ if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json'))) {
2061
+ return true;
2062
+ }
2063
+ let compileCommand = `npx tsc -p tsconfig-esm.json`;
2023
2064
  return execPromise(compileCommand, false, false, { cwd: packagePath }).then((res) => {
2024
2065
  return res === '';
2025
2066
  });
2026
2067
  });
2027
- export const compilePackageCJS = (...args_13) => __awaiter(void 0, [...args_13], void 0, function* (packagePath = process.cwd()) {
2028
- let compileCommand = `yarn exec tsc -p tsconfig-cjs.json`;
2068
+ export const compilePackageCJS = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
2069
+ // Skip packages without a tsconfig-cjs.json.
2070
+ if (!fs.existsSync(path.join(packagePath, 'tsconfig-cjs.json'))) {
2071
+ return true;
2072
+ }
2073
+ let compileCommand = `npx tsc -p tsconfig-cjs.json`;
2029
2074
  return execPromise(compileCommand, false, false, { cwd: packagePath })
2030
2075
  .then((res) => {
2031
2076
  return res === '';