@smoothbricks/nx-plugin 0.3.4 → 0.3.6

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 (32) hide show
  1. package/README.md +40 -8
  2. package/dist/bounded-test-policy.d.ts +4 -2
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +93 -15
  5. package/dist/executors/typescript-emit/executor.d.ts +17 -0
  6. package/dist/executors/typescript-emit/executor.d.ts.map +1 -0
  7. package/dist/executors/typescript-emit/executor.js +61 -0
  8. package/dist/executors/typescript-emit/schema.d.ts +5 -0
  9. package/dist/executors/typescript-emit/schema.d.ts.map +1 -0
  10. package/dist/executors/typescript-emit/schema.js +1 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +280 -29
  14. package/dist/package-target-policy.d.ts +2 -0
  15. package/dist/package-target-policy.d.ts.map +1 -1
  16. package/dist/package-target-policy.js +5 -1
  17. package/dist/workspace-config-policy.d.ts.map +1 -1
  18. package/dist/workspace-config-policy.js +11 -3
  19. package/executors.json +5 -0
  20. package/package.json +4 -3
  21. package/src/bounded-test-policy.test.ts +102 -2
  22. package/src/bounded-test-policy.ts +110 -17
  23. package/src/executors/typescript-emit/executor.test.ts +98 -0
  24. package/src/executors/typescript-emit/executor.ts +94 -0
  25. package/src/executors/typescript-emit/schema.json +19 -0
  26. package/src/executors/typescript-emit/schema.ts +4 -0
  27. package/src/index.test.ts +158 -17
  28. package/src/index.ts +358 -31
  29. package/src/package-target-policy.test.ts +17 -0
  30. package/src/package-target-policy.ts +5 -1
  31. package/src/workspace-config-policy.test.ts +41 -1
  32. package/src/workspace-config-policy.ts +12 -3
package/README.md CHANGED
@@ -4,10 +4,10 @@ Local Nx plugin for workspace-standard package setup and missing inferred target
4
4
 
5
5
  ## Target Ownership
6
6
 
7
- Official `@nx/js/typescript` owns TypeScript library inference. A package `tsconfig.lib.json` becomes the tool-output
8
- target `tsc-js`; this plugin must not duplicate or rename that target.
7
+ Official `@nx/js/typescript` inference is disabled because it cannot run the workspace's source transformers. A package
8
+ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typecheck` targets from this plugin.
9
9
 
10
- `@smoothbricks/nx-plugin` owns only inferred targets Nx does not provide here:
10
+ `@smoothbricks/nx-plugin` also owns inferred targets Nx does not provide here:
11
11
 
12
12
  - `typecheck-tests` and `typecheck-tests:watch` from `tsconfig.test.json`
13
13
  - `test:watch` from explicit `test` commands for Bun and Vitest packages
@@ -21,16 +21,48 @@ aggregates.
21
21
 
22
22
  Concrete targets come from concrete files:
23
23
 
24
- - `typecheck-tests` is inferred from `tsconfig.test.json` and runs `tsc --noEmit -p tsconfig.test.json`.
24
+ - `tsc-js` emits transformed JavaScript through a temporary JS-only `ttsc` config, then emits declarations and
25
+ declaration maps from the original project with native `tsc`. Direct project references and every cached output lane
26
+ are preserved.
27
+ - `typecheck` is inferred from `tsconfig.lib.json` and runs native `tsc -p tsconfig.lib.json --noEmit`.
28
+ - `typecheck-tests` is inferred from `tsconfig.test.json` and runs `tsc -p tsconfig.test.json --noEmit`. It first
29
+ rebuilds the current package's `tsc-js` output (or its non-TypeScript `build`) so self-imports resolve after `clean`.
25
30
  - `typecheck-tests:watch` is inferred from `tsconfig.test.json` and runs the same typecheck in watch mode.
26
31
  - `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
27
32
  the corresponding watch command and makes it depend on `typecheck-tests`.
28
33
  - A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`; workspaces with
29
34
  `cdylib` member crates also receive the cacheable `cargo-wasm` output target.
30
- - `build` is inferred only when the project has at least one concrete build target to run, such as `tsc-js` from the
31
- official TypeScript plugin, a package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on
32
- output-family wildcard targets: `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`,
33
- `*-bun`, and `*-wasm`.
35
+ - Canonical `napi` package metadata provides a host `cargo-napi` target and named release targets for each configured
36
+ triple. Linux `--use-napi-cross` targets compile C/C++ dependencies with Clang; the NAPI CLI supplies its downloaded
37
+ GNU sysroot and toolchain flags. This avoids the bundled GCC's unsupported diagnostics-color flag without disabling
38
+ the workspace's sccache wrapper.
39
+ - `build` is inferred only when the project has at least one concrete build target to run, such as inferred `tsc-js`, a
40
+ package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on output-family wildcard targets:
41
+ `*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`, `*-bun`, and `*-wasm`.
42
+
43
+ ### Dependency output lanes
44
+
45
+ Compiler targets depend on `^*-js`, not `^build`. The caret asks Nx for every matching JavaScript output target on
46
+ project dependencies; it does not directly select their Wasm, N-API, native, web, or aggregate `build` targets. This
47
+ keeps a declaration or JavaScript compile from paying for unrelated platform artifacts merely because a dependency
48
+ package publishes them.
49
+
50
+ The selected JavaScript target retains its own `dependsOn` edges. A platform artifact that is genuinely required to
51
+ produce that JavaScript therefore still participates transitively:
52
+
53
+ ```text
54
+ consumer:tsc-js
55
+ └─ dependency:bundle-js
56
+ └─ dependency:cargo-wasm
57
+ ```
58
+
59
+ A wildcard without a caret selects the current project instead. For example, a workspace may add `*-wasm` to its
60
+ `tsc-js` target default when the current package's generated Wasm module must exist during compilation. The plugin makes
61
+ this local relationship explicit for inferred `tsc-js` targets that also have inferred `cargo-wasm`. Package-managed
62
+ JavaScript targets with another platform prerequisite must likewise declare that local edge themselves.
63
+
64
+ N-API binaries are not prerequisites of TypeScript declaration emission, so compiler targets do not pull them in by
65
+ default. Aggregate `build` remains the package-completeness boundary and includes every published local output family.
34
66
 
35
67
  Do not use colon-style Nx target names such as `build:wasm` or `lint:fix`. Nx CLI syntax already uses colons for
36
68
  `project:target:configuration`, so colon target names are hard to read, easy to confuse with configurations, and awkward
@@ -1,3 +1,4 @@
1
+ import type { PackageTargetPolicyOptions, ResolvedProjectTargets } from './package-target-policy.js';
1
2
  export declare const BOUNDED_TEST_EXECUTOR = "@smoothbricks/nx-plugin:bounded-exec";
2
3
  export declare const BOUNDED_TEST_TIMEOUT_MS = 120000;
3
4
  export declare const BOUNDED_TEST_KILL_AFTER_MS = 10000;
@@ -23,10 +24,11 @@ export interface ApplyBoundedTestTargetPolicyOptions {
23
24
  projectName: string;
24
25
  defaultCommand?: string;
25
26
  projectJson?: BoundedTestPolicyProjectJson;
27
+ resolvedProject?: ResolvedProjectTargets;
26
28
  }
27
29
  export declare function applyBoundedTestTargetPolicy(packageJson: BoundedTestPolicyPackageJson, options: ApplyBoundedTestTargetPolicyOptions): void;
28
- export declare function applyWorkspaceBoundedTestTargetPolicy(root: string): boolean;
29
- export declare function checkWorkspaceBoundedTestTargetPolicy(root: string): BoundedTestPolicyIssue[];
30
+ export declare function applyWorkspaceBoundedTestTargetPolicy(root: string, options?: PackageTargetPolicyOptions): boolean;
31
+ export declare function checkWorkspaceBoundedTestTargetPolicy(root: string, options?: PackageTargetPolicyOptions): BoundedTestPolicyIssue[];
30
32
  export declare function checkBoundedTestTargetPolicy(packageJson: BoundedTestPolicyPackageJson, options: ApplyBoundedTestTargetPolicyOptions): boolean;
31
33
  export declare function boundedTestScriptAlias(projectName: string): string;
32
34
  export declare function resolveTestCommand(packageJson: BoundedTestPolicyPackageJson, defaultCommand?: string, projectJson?: BoundedTestPolicyProjectJson): string;
@@ -1 +1 @@
1
- {"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC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AAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BrH;AAED,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,0BAA+B,GACvC,sBAAsB,EAAE,CA4B1B;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAgBT;AAsFD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,4BAA4B,EACzC,cAAc,SAAa,EAC3B,WAAW,CAAC,EAAE,4BAA4B,GACzC,MAAM,CAER;AA+CD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAmC,GAAG,MAAM,CAa9G"}
@@ -29,7 +29,7 @@ export function applyBoundedTestTargetPolicy(packageJson, options) {
29
29
  packageJson.scripts ??= {};
30
30
  packageJson.scripts.test = boundedTestScriptAlias(options.projectName);
31
31
  }
32
- export function applyWorkspaceBoundedTestTargetPolicy(root) {
32
+ export function applyWorkspaceBoundedTestTargetPolicy(root, options = {}) {
33
33
  let changed = false;
34
34
  for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
35
35
  const packageJson = readPackageJson(packageJsonPath);
@@ -42,6 +42,10 @@ export function applyWorkspaceBoundedTestTargetPolicy(root) {
42
42
  if (!projectName) {
43
43
  continue;
44
44
  }
45
+ const resolvedProject = resolvedProjectFor(options, projectName);
46
+ if (checkBoundedTestTargetPolicy(packageJson, { projectName, projectJson, resolvedProject })) {
47
+ continue;
48
+ }
45
49
  const beforePackageJson = JSON.stringify(packageJson);
46
50
  const beforeProjectJson = JSON.stringify(projectJson);
47
51
  applyBoundedTestTargetPolicy(packageJson, { projectName, projectJson });
@@ -56,7 +60,7 @@ export function applyWorkspaceBoundedTestTargetPolicy(root) {
56
60
  }
57
61
  return changed;
58
62
  }
59
- export function checkWorkspaceBoundedTestTargetPolicy(root) {
63
+ export function checkWorkspaceBoundedTestTargetPolicy(root, options = {}) {
60
64
  const issues = [];
61
65
  for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
62
66
  const packageJson = readPackageJson(packageJsonPath);
@@ -73,10 +77,12 @@ export function checkWorkspaceBoundedTestTargetPolicy(root) {
73
77
  });
74
78
  continue;
75
79
  }
76
- if (!checkBoundedTestTargetPolicy(packageJson, { projectName, projectJson })) {
80
+ const resolvedProject = resolvedProjectFor(options, projectName);
81
+ if (!checkBoundedTestTargetPolicy(packageJson, { projectName, projectJson, resolvedProject })) {
77
82
  issues.push({
78
83
  path: projectJson ? projectJsonPath : packageJsonPath,
79
- message: `${projectJson ? 'targets' : 'nx.targets'}.test must use ${BOUNDED_TEST_EXECUTOR} with bounded test policy`,
84
+ message: `${projectJson ? 'targets' : 'nx.targets'}.test must use ${BOUNDED_TEST_EXECUTOR} ` +
85
+ 'or delegate through no-op targets to bounded test execution',
80
86
  });
81
87
  }
82
88
  }
@@ -84,21 +90,93 @@ export function checkWorkspaceBoundedTestTargetPolicy(root) {
84
90
  }
85
91
  export function checkBoundedTestTargetPolicy(packageJson, options) {
86
92
  const testTarget = options.projectJson ? options.projectJson.targets?.test : packageJson.nx?.targets?.test;
87
- if (!isRecord(testTarget) || testTarget.executor !== BOUNDED_TEST_EXECUTOR) {
93
+ if (!isRecord(testTarget)) {
94
+ return false;
95
+ }
96
+ if (isBoundedExecutionTarget(testTarget.executor, testTarget.options, new Set(['{projectRoot}']))) {
97
+ return packageJson.scripts?.test === boundedTestScriptAlias(options.projectName);
98
+ }
99
+ if (!isNoopAggregateTarget(testTarget)) {
100
+ return false;
101
+ }
102
+ const testScript = packageJson.scripts?.test;
103
+ if (testScript !== undefined && testScript !== boundedTestScriptAlias(options.projectName)) {
104
+ return false;
105
+ }
106
+ return resolvedAggregateTestIsBounded(options.resolvedProject);
107
+ }
108
+ function isNoopAggregateTarget(target) {
109
+ if (target.executor !== undefined && target.executor !== 'nx:noop') {
110
+ return false;
111
+ }
112
+ if (typeof target.command === 'string' || (isRecord(target.options) && typeof target.options.command === 'string')) {
113
+ return false;
114
+ }
115
+ return Array.isArray(target.dependsOn) && target.dependsOn.length > 0;
116
+ }
117
+ function isBoundedExecutionTarget(executor, rawOptions, allowedCwds) {
118
+ if (executor !== BOUNDED_TEST_EXECUTOR || !isRecord(rawOptions)) {
88
119
  return false;
89
120
  }
90
- const targetOptions = testTarget.options;
91
- if (!isRecord(targetOptions) ||
92
- typeof targetOptions.command !== 'string' ||
93
- targetOptions.command.length === 0 ||
94
- isPackageTestScriptRunnerCommand(targetOptions.command) ||
95
- targetOptions.command !== ensureBunTestTimeoutFlag(targetOptions.command) ||
96
- targetOptions.cwd !== '{projectRoot}' ||
97
- targetOptions.timeoutMs !== BOUNDED_TEST_TIMEOUT_MS ||
98
- targetOptions.killAfterMs !== BOUNDED_TEST_KILL_AFTER_MS) {
121
+ const command = rawOptions.command;
122
+ return (typeof command === 'string' &&
123
+ command.length > 0 &&
124
+ isPackageTestScriptRunnerCommand(command) === false &&
125
+ command === ensureBunTestTimeoutFlag(command) &&
126
+ typeof rawOptions.cwd === 'string' &&
127
+ allowedCwds.has(rawOptions.cwd) &&
128
+ rawOptions.timeoutMs === BOUNDED_TEST_TIMEOUT_MS &&
129
+ rawOptions.killAfterMs === BOUNDED_TEST_KILL_AFTER_MS);
130
+ }
131
+ function resolvedAggregateTestIsBounded(project) {
132
+ if (!project?.targetDependencies || !project.targetExecutors || !project.targetOptions) {
99
133
  return false;
100
134
  }
101
- return packageJson.scripts?.test === boundedTestScriptAlias(options.projectName);
135
+ const visiting = new Set();
136
+ const verified = new Map();
137
+ const allowedCwds = new Set(['{projectRoot}', ...(project.root ? [project.root] : [])]);
138
+ const visit = (targetName) => {
139
+ const cached = verified.get(targetName);
140
+ if (cached !== undefined) {
141
+ return cached;
142
+ }
143
+ if (visiting.has(targetName) || !project.targets.has(targetName)) {
144
+ return false;
145
+ }
146
+ visiting.add(targetName);
147
+ const executor = project.targetExecutors?.get(targetName);
148
+ let valid;
149
+ if (executor !== undefined && executor !== 'nx:noop') {
150
+ valid = isBoundedExecutionTarget(executor, project.targetOptions?.get(targetName), allowedCwds);
151
+ }
152
+ else {
153
+ const dependencies = project.targetDependencies?.get(targetName) ?? [];
154
+ valid =
155
+ dependencies.length > 0 &&
156
+ dependencies.every((dependency) => {
157
+ const matches = matchingResolvedTargets(dependency, project.targets);
158
+ return matches.length > 0 && matches.every(visit);
159
+ });
160
+ }
161
+ visiting.delete(targetName);
162
+ verified.set(targetName, valid);
163
+ return valid;
164
+ };
165
+ return visit('test');
166
+ }
167
+ function matchingResolvedTargets(dependency, targets) {
168
+ if (dependency.startsWith('^')) {
169
+ return [];
170
+ }
171
+ if (!dependency.startsWith('*')) {
172
+ return targets.has(dependency) ? [dependency] : [];
173
+ }
174
+ const suffix = dependency.slice(1);
175
+ return [...targets].filter((targetName) => targetName.endsWith(suffix));
176
+ }
177
+ function resolvedProjectFor(options, projectName) {
178
+ const project = options.resolvedTargetsByProject?.get(projectName);
179
+ return project && 'targets' in project ? project : undefined;
102
180
  }
103
181
  export function boundedTestScriptAlias(projectName) {
104
182
  return `nx run ${projectName}:test --outputStyle=stream`;
@@ -0,0 +1,17 @@
1
+ import type { TypeScriptEmitOptions } from './schema.js';
2
+ interface TypeScriptEmitContext {
3
+ root: string;
4
+ }
5
+ interface TypeScriptEmitResult {
6
+ success: boolean;
7
+ }
8
+ export interface CompilerInvocation {
9
+ command: 'tsc' | 'ttsc';
10
+ args: string[];
11
+ cwd: string;
12
+ }
13
+ export type CompilerRunner = (invocation: CompilerInvocation) => Promise<boolean>;
14
+ export default function typescriptEmitExecutor(options: TypeScriptEmitOptions, context: TypeScriptEmitContext): Promise<TypeScriptEmitResult>;
15
+ export declare function runTypeScriptEmit(options: TypeScriptEmitOptions, context: TypeScriptEmitContext, runner: CompilerRunner): Promise<TypeScriptEmitResult>;
16
+ export {};
17
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/executor.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAMD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAElF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAqC/B"}
@@ -0,0 +1,61 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { once } from 'node:events';
4
+ import { rm, writeFile } from 'node:fs/promises';
5
+ import { basename, dirname, isAbsolute, join } from 'node:path';
6
+ import { readJsonFile } from 'nx/src/devkit-exports.js';
7
+ export default function typescriptEmitExecutor(options, context) {
8
+ return runTypeScriptEmit(options, context, runCompiler);
9
+ }
10
+ export async function runTypeScriptEmit(options, context, runner) {
11
+ const cwd = isAbsolute(options.cwd) ? options.cwd : join(context.root, options.cwd);
12
+ const tsConfigPath = isAbsolute(options.tsConfig) ? options.tsConfig : join(cwd, options.tsConfig);
13
+ const tsConfig = readJsonFile(tsConfigPath);
14
+ const overlayPath = join(dirname(tsConfigPath), `.ttsc-js-${process.pid}-${randomUUID()}.json`);
15
+ const overlay = {
16
+ extends: `./${basename(tsConfigPath)}`,
17
+ compilerOptions: {
18
+ composite: false,
19
+ declaration: false,
20
+ declarationMap: false,
21
+ emitDeclarationOnly: false,
22
+ incremental: false,
23
+ },
24
+ ...(Array.isArray(tsConfig.references) ? { references: tsConfig.references } : {}),
25
+ };
26
+ await writeFile(overlayPath, `${JSON.stringify(overlay, null, 2)}\n`, { flag: 'wx' });
27
+ try {
28
+ const javascriptSucceeded = await runner({
29
+ command: 'ttsc',
30
+ args: ['-p', overlayPath, '--emit'],
31
+ cwd,
32
+ });
33
+ if (!javascriptSucceeded) {
34
+ return { success: false };
35
+ }
36
+ const declarationsSucceeded = await runner({
37
+ command: 'tsc',
38
+ args: ['-p', overlayPath, '--emitDeclarationOnly', '--declaration', '--declarationMap'],
39
+ cwd,
40
+ });
41
+ return { success: declarationsSucceeded };
42
+ }
43
+ finally {
44
+ await rm(overlayPath, { force: true });
45
+ }
46
+ }
47
+ async function runCompiler(invocation) {
48
+ const child = spawn(invocation.command, invocation.args, {
49
+ cwd: invocation.cwd,
50
+ stdio: 'inherit',
51
+ windowsHide: true,
52
+ });
53
+ try {
54
+ await once(child, 'exit');
55
+ return child.exitCode === 0 && child.signalCode === null;
56
+ }
57
+ catch (error) {
58
+ console.error(`${invocation.command}: ${error instanceof Error ? error.message : String(error)}`);
59
+ return false;
60
+ }
61
+ }
@@ -0,0 +1,5 @@
1
+ export interface TypeScriptEmitOptions {
2
+ cwd: string;
3
+ tsConfig: string;
4
+ }
5
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CreateNodesV2 } from 'nx/src/devkit-exports.js';
1
+ import { type CreateNodesV2 } from 'nx/src/devkit-exports.js';
2
2
  export declare const createNodesV2: CreateNodesV2;
3
3
  declare const _default: {
4
4
  createNodesV2: CreateNodesV2;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAiDxG,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AA2GlC,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}