@_linked/cli 1.31.0 → 1.32.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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#181](https://github.com/linked-fw/cli/pull/181) [`adb992a`](https://github.com/linked-fw/cli/commit/adb992aad55399ff8daee4888cff97c01302e7fc) Thanks [@flyon](https://github.com/flyon)! - `linked build` now enforces the shape-registration standard: every package registers its whole
8
+ shape set through `src/shapes/index.ts`, and apps load it with `import '<pkg>/shapes/index'`.
9
+
10
+ Two new build steps, after "Checking shape references":
11
+
12
+ - **Checking shapes/index** loads `lib/esm/shapes/index.js` on its own in a fresh process and fails
13
+ when it misses any of the package's shapes that its shape modules register when each is loaded
14
+ alone (the per-module loads are shared with the shape-references check, not repeated). It also
15
+ fails when the package has shapes but no `shapes/index`, or when the index throws on load. The
16
+ error lists the missing shapes and the exact `import './X.js';` lines to add. A package without
17
+ shapes passes.
18
+ - **Checking sideEffects** fails when `package.json` `sideEffects` is `false`, or is a list that
19
+ does not match every `lib/esm/shapes/**/*.js`: a bundler drops a side-effect-only import of a
20
+ module declared side-effect-free, so the index would register nothing in production. The error
21
+ names the uncovered modules and what to write instead (omit the field, or
22
+ `["lib/esm/shapes/index.js", "lib/esm/shapes/*.js"]`).
23
+
24
+ `linked create-shape` now writes to the `src/shapes/index.ts` next to the source folder it created
25
+ the shape in, rather than the one under the current directory. The package template's
26
+ `shapes/index.ts` states the side-effect-imports-only rule, and the React Native template's shapes
27
+ package gains a `src/shapes/index.ts` that its entry imports.
28
+
29
+ The shape-references check no longer tolerates `@_linked/core`'s `PropertyShape.in -> List`: core
30
+ now registers `List` wherever `PropertyShape` is registered, so the known-unresolved list is empty
31
+ and that reference fails the build like any other.
32
+
3
33
  ## 1.31.0
4
34
 
5
35
  ### Minor Changes
@@ -1,2 +1,4 @@
1
1
  import './package';
2
+ // Registers every shape in the package.
3
+ import './shapes/index';
2
4
  export * from './shapes/Example';
@@ -0,0 +1,5 @@
1
+ // Shape registry: one side-effect import per shape module, so loading this file
2
+ // registers every shape in the package. Imports only — no exports. `linked build`
3
+ // fails when a shape module is missing from this list.
4
+ // Extensionless on purpose: Metro does not map `.js` specifiers to `.ts` source.
5
+ import './Example';
@@ -1,5 +1,7 @@
1
1
  // Shape registry — every shape in this package is imported here so its @linkedShape
2
2
  // decorator runs and the shape registers on BOTH boot paths: the backend entry
3
3
  // (src/backend.ts, which materializes shapes into app-data on boot) and the frontend
4
- // entry. `linked create-shape` maintains the list below.
4
+ // entry. Apps load the whole set with `import '<package>/shapes/index'`.
5
+ // Side-effect imports only: no exports, components or providers. `linked create-shape`
6
+ // maintains the list below, and `linked build` fails when a shape module is missing.
5
7
  //SHAPES
@@ -1 +1 @@
1
- {"version":3,"file":"cli-methods.d.ts","sourceRoot":"","sources":["../../src/cli-methods.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAepD;;;;;;GAMG;AAKH,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,GACb,CAAC;AAoBF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,cAAc,CAAC;AAEjD,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,SAAI,EAAE,iBAAwB,EAAE,UAAS;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,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BAAW,EAAE,YAAO,SAsCnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,gBAAW,qBA8B/C,CAAC"}
@@ -20,7 +20,8 @@ import { planPackageSetup } from './utils/packageSetup.js';
20
20
  import { detectPackageManager, execBinCommand, runScriptCommand, } from './utils/packageManager.js';
21
21
  import { rewriteExtensionlessImports } from './utils/esmSpecifiers.js';
22
22
  import { checkShapeNames } from './utils/shapeNames.js';
23
- import { checkShapeReferences } from './utils/shapeReferences.js';
23
+ import { checkShapeReferences, inspectShapeReferences, } from './utils/shapeReferences.js';
24
+ import { checkShapesIndex, checkShapesSideEffects } from './utils/shapesIndex.js';
24
25
  import { spawn as spawnChild } from 'child_process';
25
26
  import { findNearestPackageJson } from 'find-nearest-package-json';
26
27
  import { statSync } from 'fs';
@@ -1074,8 +1075,12 @@ export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void
1074
1075
  // The shapes barrel (src/shapes/index.ts) is imported by both the frontend index and
1075
1076
  // the backend entry, so every shape registers on both boot paths (and materializes into
1076
1077
  // app-data on boot). `create-shape` adds each new shape here — NOT to the main index.
1078
+ // It holds side-effect imports only (no exports), in packages and apps alike: apps load a
1079
+ // package's whole set with `import '<pkg>/shapes/index'`, and `linked build` fails a
1080
+ // package whose shapes/index misses one of its shapes.
1077
1081
  const SHAPES_BARREL_HEADER = `// Shape registry — every shape is imported here so its @linkedShape decorator runs and\n` +
1078
- `// the shape registers on both boot paths (backend materialization + frontend). \`linked\n` +
1082
+ `// the shape registers on both boot paths (backend materialization + frontend).\n` +
1083
+ `// Side-effect imports only: no exports, components or providers. \`linked\n` +
1079
1084
  `// create-shape\` maintains this list.\n//SHAPES\n`;
1080
1085
  const ensureBackendImportsShapes = function (root = process.cwd()) {
1081
1086
  const backendPath = path.join(root, 'src', 'backend.ts');
@@ -1266,7 +1271,9 @@ export const createShape = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...
1266
1271
  // Register the shape in the shapes barrel (src/shapes/index.ts) — NOT the main index —
1267
1272
  // and make sure the barrel is loaded on both boot paths. This is what makes the app
1268
1273
  // materialize its own shapes on boot.
1269
- const barrelPath = addShapeToBarrel(hyphenName);
1274
+ // The barrel sits next to the shape: in the source folder's parent, not the cwd, which
1275
+ // is only the same folder when the command runs from the package or app root.
1276
+ const barrelPath = addShapeToBarrel(hyphenName, path.dirname(sourceFolder));
1270
1277
  log(`Registered the shape in ${chalk.magenta(barrelPath.replace(basePath, ''))}`);
1271
1278
  });
1272
1279
  export const createSetComponent = (name_1, ...args_1) => __awaiter(void 0, [name_1, ...args_1], void 0, function* (name, basePath = process.cwd()) {
@@ -2169,130 +2176,149 @@ const loadServerClass = () => __awaiter(void 0, void 0, void 0, function* () {
2169
2176
  `Install it, or run the frontend only.\nCause: ${err instanceof Error ? err.message : err}`);
2170
2177
  }
2171
2178
  });
2172
- export const planBuildSteps = (pkgJson, packagePath) => [
2173
- {
2174
- name: 'Checking imports',
2175
- apply: () => checkImports(packagePath + '/src'),
2176
- },
2177
- {
2178
- name: 'Compiling ESM',
2179
- apply: () => __awaiter(void 0, void 0, void 0, function* () {
2180
- return compilePackageESM(packagePath);
2181
- }),
2182
- },
2183
- {
2184
- name: 'Compiling CJS',
2185
- apply: () => __awaiter(void 0, void 0, void 0, function* () {
2186
- return compilePackageCJS(packagePath);
2187
- }),
2188
- },
2189
- {
2190
- name: 'Copying files to lib folder',
2191
- apply: () => __awaiter(void 0, void 0, void 0, function* () {
2192
- const files = yield glob(packagePath + '/src/**/*.{json,d.ts,css,scss}');
2193
- let cjsPublished = false;
2194
- try {
2195
- cjsPublished = packagePublishesCjs(JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8')));
2196
- }
2197
- catch (_a) { }
2198
- return Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
2179
+ export const planBuildSteps = (pkgJson, packagePath) => {
2180
+ // Loading every shape module in a child process of its own is the slow part of
2181
+ // a build; the shape checks below share one run, started by the first to ask.
2182
+ let inspection;
2183
+ const inspectShapes = () => (inspection !== null && inspection !== void 0 ? inspection : (inspection = inspectShapeReferences(packagePath)));
2184
+ return [
2185
+ {
2186
+ name: 'Checking imports',
2187
+ apply: () => checkImports(packagePath + '/src'),
2188
+ },
2189
+ {
2190
+ name: 'Compiling ESM',
2191
+ apply: () => __awaiter(void 0, void 0, void 0, function* () {
2192
+ return compilePackageESM(packagePath);
2193
+ }),
2194
+ },
2195
+ {
2196
+ name: 'Compiling CJS',
2197
+ apply: () => __awaiter(void 0, void 0, void 0, function* () {
2198
+ return compilePackageCJS(packagePath);
2199
+ }),
2200
+ },
2201
+ {
2202
+ name: 'Copying files to lib folder',
2203
+ apply: () => __awaiter(void 0, void 0, void 0, function* () {
2204
+ const files = yield glob(packagePath + '/src/**/*.{json,d.ts,css,scss}');
2205
+ let cjsPublished = false;
2199
2206
  try {
2200
- yield fs.copy(file, packagePath +
2201
- '/lib/esm/' +
2202
- file.replace(packagePath + '/src/', ''));
2203
- // Only mirror into lib/cjs when there is a CJS build to mirror.
2204
- if (cjsPublished) {
2207
+ cjsPublished = packagePublishesCjs(JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8')));
2208
+ }
2209
+ catch (_a) { }
2210
+ return Promise.all(files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
2211
+ try {
2205
2212
  yield fs.copy(file, packagePath +
2206
- '/lib/cjs/' +
2213
+ '/lib/esm/' +
2207
2214
  file.replace(packagePath + '/src/', ''));
2215
+ // Only mirror into lib/cjs when there is a CJS build to mirror.
2216
+ if (cjsPublished) {
2217
+ yield fs.copy(file, packagePath +
2218
+ '/lib/cjs/' +
2219
+ file.replace(packagePath + '/src/', ''));
2220
+ }
2221
+ return true;
2222
+ }
2223
+ catch (err) {
2224
+ console.warn(err);
2225
+ return false;
2208
2226
  }
2227
+ }))).then((allResults) => {
2228
+ return allResults.every((r) => r === true);
2229
+ });
2230
+ }),
2231
+ },
2232
+ {
2233
+ name: 'Dual package support',
2234
+ apply: () => {
2235
+ // Skip if no tsconfig files (e.g. pure-CSS packages).
2236
+ if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json')) ||
2237
+ !fs.existsSync(path.join(packagePath, 'tsconfig-cjs.json'))) {
2238
+ return Promise.resolve(true);
2239
+ }
2240
+ // Nothing to make dual when only one format is published — otherwise this
2241
+ // leaves a lib/cjs holding a lone `{"type":"commonjs"}` marker and no code.
2242
+ try {
2243
+ if (!packagePublishesCjs(JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8')))) {
2244
+ return Promise.resolve(true);
2245
+ }
2246
+ }
2247
+ catch (_a) { }
2248
+ // Resolve the binary from the nearest node_modules (supports both
2249
+ // per-package and workspace-root installs of tsconfig-to-dual-package).
2250
+ return execPromise('npx tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
2251
+ return res === '';
2252
+ });
2253
+ },
2254
+ },
2255
+ {
2256
+ name: 'Removing old files from lib folder',
2257
+ apply: () => __awaiter(void 0, void 0, void 0, function* () {
2258
+ return removeOldFiles(packagePath);
2259
+ }),
2260
+ },
2261
+ {
2262
+ // MUST run after 'Copying files to lib folder' and after 'Removing old
2263
+ // files from lib folder', because the rewrite resolves each specifier
2264
+ // against the files actually present in lib/esm:
2265
+ // - the copy step brings in the assets (`./x.scss`) and hand-written
2266
+ // `.d.ts` from src; before it, an asset import looks unresolvable (a
2267
+ // spurious "build with warnings") and a copied `.d.ts` is never rewritten;
2268
+ // - the cleanup step deletes stale output; before it, a leftover `x.js`
2269
+ // makes './x' resolve to './x.js' and the cleanup then removes the file
2270
+ // the specifier now points at.
2271
+ name: 'Rewriting ESM import specifiers',
2272
+ apply: () => __awaiter(void 0, void 0, void 0, function* () {
2273
+ // No tsconfig-esm.json means the ESM compile was skipped (e.g. pure-CSS
2274
+ // packages), so there is nothing to rewrite and nothing to fail over.
2275
+ if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json'))) {
2209
2276
  return true;
2210
2277
  }
2211
- catch (err) {
2212
- console.warn(err);
2213
- return false;
2278
+ const libEsm = path.join(packagePath, 'lib', 'esm');
2279
+ if (!fs.existsSync(libEsm)) {
2280
+ return {
2281
+ error: 'lib/esm was not emitted while tsconfig-esm.json is present. Check the ESM compile.',
2282
+ };
2214
2283
  }
2215
- }))).then((allResults) => {
2216
- return allResults.every((r) => r === true);
2217
- });
2218
- }),
2219
- },
2220
- {
2221
- name: 'Dual package support',
2222
- apply: () => {
2223
- // Skip if no tsconfig files (e.g. pure-CSS packages).
2224
- if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json')) ||
2225
- !fs.existsSync(path.join(packagePath, 'tsconfig-cjs.json'))) {
2226
- return Promise.resolve(true);
2227
- }
2228
- // Nothing to make dual when only one format is published — otherwise this
2229
- // leaves a lib/cjs holding a lone `{"type":"commonjs"}` marker and no code.
2230
- try {
2231
- if (!packagePublishesCjs(JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8')))) {
2232
- return Promise.resolve(true);
2284
+ const { changed, unresolved } = yield rewriteExtensionlessImports(libEsm);
2285
+ if (unresolved.length > 0) {
2286
+ return `could not resolve ${unresolved.length} import(s), left unchanged: ${unresolved.join(', ')}`;
2233
2287
  }
2234
- }
2235
- catch (_a) { }
2236
- // Resolve the binary from the nearest node_modules (supports both
2237
- // per-package and workspace-root installs of tsconfig-to-dual-package).
2238
- return execPromise('npx tsconfig-to-dual-package ./tsconfig-cjs.json ./tsconfig-esm.json', false, false, { cwd: packagePath }).then((res) => {
2239
- return res === '';
2240
- });
2288
+ return changed > 0 ? { info: `rewrote ${changed} file(s)` } : true;
2289
+ }),
2241
2290
  },
2242
- },
2243
- {
2244
- name: 'Removing old files from lib folder',
2245
- apply: () => __awaiter(void 0, void 0, void 0, function* () {
2246
- return removeOldFiles(packagePath);
2247
- }),
2248
- },
2249
- {
2250
- // MUST run after 'Copying files to lib folder' and after 'Removing old
2251
- // files from lib folder', because the rewrite resolves each specifier
2252
- // against the files actually present in lib/esm:
2253
- // - the copy step brings in the assets (`./x.scss`) and hand-written
2254
- // `.d.ts` from src; before it, an asset import looks unresolvable (a
2255
- // spurious "build with warnings") and a copied `.d.ts` is never rewritten;
2256
- // - the cleanup step deletes stale output; before it, a leftover `x.js`
2257
- // makes './x' resolve to './x.js' and the cleanup then removes the file
2258
- // the specifier now points at.
2259
- name: 'Rewriting ESM import specifiers',
2260
- apply: () => __awaiter(void 0, void 0, void 0, function* () {
2261
- // No tsconfig-esm.json means the ESM compile was skipped (e.g. pure-CSS
2262
- // packages), so there is nothing to rewrite and nothing to fail over.
2263
- if (!fs.existsSync(path.join(packagePath, 'tsconfig-esm.json'))) {
2264
- return true;
2265
- }
2266
- const libEsm = path.join(packagePath, 'lib', 'esm');
2267
- if (!fs.existsSync(libEsm)) {
2268
- return {
2269
- error: 'lib/esm was not emitted while tsconfig-esm.json is present. Check the ESM compile.',
2270
- };
2271
- }
2272
- const { changed, unresolved } = yield rewriteExtensionlessImports(libEsm);
2273
- if (unresolved.length > 0) {
2274
- return `could not resolve ${unresolved.length} import(s), left unchanged: ${unresolved.join(', ')}`;
2275
- }
2276
- return changed > 0 ? { info: `rewrote ${changed} file(s)` } : true;
2277
- }),
2278
- },
2279
- {
2280
- // Reads the emitted lib/esm, so it runs after everything that writes it.
2281
- name: 'Checking shape names',
2282
- apply: () => checkShapeNames(packagePath),
2283
- },
2284
- {
2285
- // Loads each compiled shape module on its own, so it needs the final
2286
- // lib/esm too. Fails the build: an unresolved reference is a query that
2287
- // throws "Shape class not found" in a consumer's bundle.
2288
- name: 'Checking shape references',
2289
- apply: () => checkShapeReferences(packagePath),
2290
- },
2291
- {
2292
- name: 'Checking dependencies',
2293
- apply: () => depCheck(packagePath),
2294
- },
2295
- ];
2291
+ {
2292
+ // Reads the emitted lib/esm, so it runs after everything that writes it.
2293
+ name: 'Checking shape names',
2294
+ apply: () => checkShapeNames(packagePath),
2295
+ },
2296
+ {
2297
+ // Loads each compiled shape module on its own, so it needs the final
2298
+ // lib/esm too. Fails the build: an unresolved reference is a query that
2299
+ // throws "Shape class not found" in a consumer's bundle.
2300
+ name: 'Checking shape references',
2301
+ apply: () => checkShapeReferences(packagePath, undefined, inspectShapes()),
2302
+ },
2303
+ {
2304
+ // Same per-module loads: loading lib/esm/shapes/index.js alone must register
2305
+ // every shape of this package that its shape modules register one by one,
2306
+ // because apps load a package's shapes with `import '<pkg>/shapes/index'`.
2307
+ name: 'Checking shapes/index',
2308
+ apply: () => checkShapesIndex(packagePath, undefined, inspectShapes()),
2309
+ },
2310
+ {
2311
+ // A bundler drops the side-effect-only imports in shapes/index of a module
2312
+ // package.json calls side-effect-free.
2313
+ name: 'Checking sideEffects',
2314
+ apply: () => __awaiter(void 0, void 0, void 0, function* () { return checkShapesSideEffects(packagePath); }),
2315
+ },
2316
+ {
2317
+ name: 'Checking dependencies',
2318
+ apply: () => depCheck(packagePath),
2319
+ },
2320
+ ];
2321
+ };
2296
2322
  export const compilePackage = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (packagePath = process.cwd()) {
2297
2323
  //echo 'compiling CJS' && tsc -p tsconfig-cjs.json && echo 'compiling ESM' && tsc -p tsconfig-esm.json
2298
2324
  // let cjsConfig = fs.existsSync(path.join(packagePath,'tsconfig-cjs.json'));