@smoothbricks/nx-plugin 0.4.12 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/index.js +25 -20
- package/package.json +1 -1
- package/src/index.test.ts +34 -8
- package/src/index.ts +28 -20
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
|
|
|
13
13
|
- `test:watch` from explicit `test` commands for Bun and Vitest packages
|
|
14
14
|
- Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
|
|
15
15
|
- aggregate `build` and `lint` targets
|
|
16
|
-
- an uncached `deploy` for a project with a wrangler manifest, running
|
|
16
|
+
- an uncached `deploy` for a PRIVATE project with a wrangler manifest, running
|
|
17
|
+
`smoo wrangler deploy-stage --stage {args.stage}`
|
|
17
18
|
|
|
18
19
|
The deploy is one target that takes whichever stage it is given, never a configuration per stage: pull-request stages
|
|
19
20
|
are `prN` for unbounded N, so `nx run <project>:deploy --stage=pr42` has to work for a stage no enumeration could list.
|
|
@@ -22,6 +23,12 @@ Declaring `deploy` locally overrides only the properties it names, so a project
|
|
|
22
23
|
`"dependsOn": ["...", "backend:deploy"]` and keeps the inferred command; a project that declares `deploy-build` gets
|
|
23
24
|
that edge instead of `build`, and the plugin caches that half without inventing its command.
|
|
24
25
|
|
|
26
|
+
`private: true` is half the detection, because a wrangler manifest alone does not mean deployable: a published library
|
|
27
|
+
ships one to document the Durable Object binding it implements, and that manifest carries the same `name`, `main` and
|
|
28
|
+
`compatibility_date` a deployable worker's does. So the inferred target goes to packages npm will never publish, and a
|
|
29
|
+
published package that really is deployed declares `deploy` itself. Whether CI deploys any of them is a separate
|
|
30
|
+
question, answered only by the deploy tags the CLI reads (`stage-deploy-target` and its three siblings).
|
|
31
|
+
|
|
25
32
|
Lint commands are inferred per project. A workspace Biome configuration enables the project-wide Biome check; an ESLint
|
|
26
33
|
flat configuration enables ESLint only for existing JavaScript/TypeScript files under that project's `src`. Rust-only
|
|
27
34
|
source trees therefore keep their Cargo validation and manifest checks without invoking ESLint on nonexistent JavaScript
|
package/dist/index.js
CHANGED
|
@@ -618,20 +618,22 @@ function packageBinOutputs(packageJson, packageJsonPath) {
|
|
|
618
618
|
}
|
|
619
619
|
/**
|
|
620
620
|
* The deployment manifests wrangler itself looks for, in its own precedence
|
|
621
|
-
* order. Finding one
|
|
622
|
-
*
|
|
621
|
+
* order. Finding one is HALF the detection: a published library ships one to
|
|
622
|
+
* document a Durable Object binding for its consumers, and that manifest is
|
|
623
|
+
* structurally indistinguishable from a deployable worker's — same `name`,
|
|
624
|
+
* `main` and `compatibility_date`. So presence alone cannot mean deployable,
|
|
625
|
+
* and the other half is `private: true` below.
|
|
623
626
|
*
|
|
624
627
|
* Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
|
|
625
628
|
* belongs to the CLI, which reads it to decide which secrets a stage requires; a
|
|
626
629
|
* second copy in the graph would disagree the first time a stage was added. And
|
|
627
|
-
* which stages CI actually runs is the four-way vocabulary in the CLI's
|
|
630
|
+
* which stages CI actually runs is the four-way tag vocabulary in the CLI's
|
|
628
631
|
* `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
|
|
629
|
-
* that a flag here could express exactly one of. So
|
|
630
|
-
* the target, and
|
|
632
|
+
* that a flag here could express exactly one of. So a private wrangler project
|
|
633
|
+
* gets the target, and the tags alone decide what CI deploys.
|
|
631
634
|
*
|
|
632
635
|
* A worker deployed by some other mechanism declares its own `options.command`,
|
|
633
|
-
* which replaces this one;
|
|
634
|
-
* it, because the `deploy-stage` string went with it.
|
|
636
|
+
* which replaces this one; the tag is what CI reads either way.
|
|
635
637
|
*/
|
|
636
638
|
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
637
639
|
/**
|
|
@@ -640,11 +642,10 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
|
|
|
640
642
|
* `configurations` map cannot describe the surface that actually exists, and a
|
|
641
643
|
* project carrying both spellings would have two ways to say one thing.
|
|
642
644
|
*
|
|
643
|
-
* No `stage-deploy-target` tag either, deliberately: the
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* answers, and the two would drift the first time either moved.
|
|
645
|
+
* No `stage-deploy-target` tag either, deliberately: that tag is the repository's
|
|
646
|
+
* statement that CI deploys this project on every stage, and only the repository
|
|
647
|
+
* can make it. A plugin that tagged what it inferred would enrol every private
|
|
648
|
+
* wrangler project in CI deploys by writing the policy it is supposed to read.
|
|
648
649
|
*
|
|
649
650
|
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
650
651
|
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
@@ -696,7 +697,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
696
697
|
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
697
698
|
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
698
699
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
699
|
-
const
|
|
700
|
+
const isDeployableWranglerProject = packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
700
701
|
if (hasLibTsconfig) {
|
|
701
702
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
702
703
|
// Dependency packages may publish bundled entries that raw tsc does not produce.
|
|
@@ -1198,16 +1199,19 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1198
1199
|
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
|
|
1199
1200
|
// measured, not assumed, against an inferred base.
|
|
1200
1201
|
//
|
|
1201
|
-
// `deploy` is INFERRED for a wrangler project rather than patched onto a hand-written
|
|
1202
|
-
// command is a constant of the convention, not of the project: every consumer wrote
|
|
1203
|
-
// `nx:run-commands` wrapper around it
|
|
1204
|
-
// a
|
|
1205
|
-
//
|
|
1206
|
-
//
|
|
1202
|
+
// `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
|
|
1203
|
+
// one. The command is a constant of the convention, not of the project: every consumer wrote
|
|
1204
|
+
// the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
|
|
1205
|
+
// detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
|
|
1206
|
+
// so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
|
|
1207
|
+
// one `nx run-many -t deploy` away. A published package that really is deployed declares
|
|
1208
|
+
// `deploy` itself. `deploy-build` stays declaration-driven in the other direction, because
|
|
1209
|
+
// only the project knows what building it means — the plugin supplies its POLICY (cache
|
|
1210
|
+
// honestly) and nothing else.
|
|
1207
1211
|
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
1208
1212
|
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
1209
1213
|
}
|
|
1210
|
-
if (
|
|
1214
|
+
if (isDeployableWranglerProject) {
|
|
1211
1215
|
// Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
|
|
1212
1216
|
// target the project lacks — measured, the task just runs alone — and a wrangler worker can
|
|
1213
1217
|
// legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
|
|
@@ -1634,6 +1638,7 @@ async function readPackageJson(packageJsonPath) {
|
|
|
1634
1638
|
...('bin' in parsed ? { bin: parsed.bin } : {}),
|
|
1635
1639
|
...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
|
|
1636
1640
|
...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
|
|
1641
|
+
...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
|
|
1637
1642
|
...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
|
|
1638
1643
|
...(rawNx
|
|
1639
1644
|
? {
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -1659,10 +1659,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1659
1659
|
}
|
|
1660
1660
|
});
|
|
1661
1661
|
|
|
1662
|
-
it('gives a wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
1662
|
+
it('gives a private wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
1663
1663
|
const workspace = await createWorkspace();
|
|
1664
1664
|
try {
|
|
1665
|
-
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1665
|
+
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
1666
1666
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1667
1667
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1668
1668
|
|
|
@@ -1672,9 +1672,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1672
1672
|
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
1673
1673
|
cwd: 'packages/site',
|
|
1674
1674
|
});
|
|
1675
|
-
// That exact string is load-bearing beyond running: the CLI's `isStageDerivedDeploy`
|
|
1676
|
-
// recognises a stage deploy by it, which is why the plugin emits it instead of asking
|
|
1677
|
-
// every consumer to retype it and drift.
|
|
1678
1675
|
// A cache hit on deploy would mean "we once uploaded this hash", which a rollback falsifies
|
|
1679
1676
|
// silently; the step has to run and read live state instead.
|
|
1680
1677
|
expect(targets.deploy?.cache).toBe(false);
|
|
@@ -1687,13 +1684,38 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1687
1684
|
}
|
|
1688
1685
|
});
|
|
1689
1686
|
|
|
1687
|
+
it('infers no deploy for a PUBLISHED package whose wrangler manifest documents a binding', async () => {
|
|
1688
|
+
const workspace = await createWorkspace();
|
|
1689
|
+
try {
|
|
1690
|
+
// The shape that regressed a consumer: a library published to npm that ships a wrangler
|
|
1691
|
+
// manifest so consumers can declare the Durable Object binding it implements. Structurally
|
|
1692
|
+
// identical to a worker's, so only the manifest's own `private` flag tells them apart.
|
|
1693
|
+
await workspace.write(
|
|
1694
|
+
'packages/acme-cloudflare/package.json',
|
|
1695
|
+
'{"name":"@acme/cloudflare","nx":{"tags":["npm:private"]}}\n',
|
|
1696
|
+
);
|
|
1697
|
+
await workspace.write(
|
|
1698
|
+
'packages/acme-cloudflare/wrangler.toml',
|
|
1699
|
+
'# Wrangler configuration for @acme/cloudflare Durable Object\nname = "acme-cloudflare"\nmain = "src/index.ts"\ncompatibility_date = "2025-01-01"\n',
|
|
1700
|
+
);
|
|
1701
|
+
const targets = await inferProjectTargets(workspace, 'packages/acme-cloudflare/package.json');
|
|
1702
|
+
|
|
1703
|
+
expect(Object.keys(targets)).not.toContain('deploy');
|
|
1704
|
+
} finally {
|
|
1705
|
+
await workspace.cleanup();
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1690
1709
|
it('points an inferred deploy at the declared deploy-build, and caches that half', async () => {
|
|
1691
1710
|
const workspace = await createWorkspace();
|
|
1692
1711
|
const declared = {
|
|
1693
1712
|
'deploy-build': { executor: 'nx:run-commands', options: { command: 'bun tooling/build-site.ts' } },
|
|
1694
1713
|
};
|
|
1695
1714
|
try {
|
|
1696
|
-
await workspace.write(
|
|
1715
|
+
await workspace.write(
|
|
1716
|
+
'packages/site/package.json',
|
|
1717
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1718
|
+
);
|
|
1697
1719
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1698
1720
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1699
1721
|
|
|
@@ -1712,7 +1734,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1712
1734
|
it('falls back to the aggregate build when a wrangler project emits one', async () => {
|
|
1713
1735
|
const workspace = await createWorkspace();
|
|
1714
1736
|
try {
|
|
1715
|
-
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1737
|
+
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
1716
1738
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1717
1739
|
// tsconfig.lib.json is what puts an emitting target, and so the `build` aggregate, on a project.
|
|
1718
1740
|
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
@@ -1733,7 +1755,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1733
1755
|
deploy: { dependsOn: ['...', { projects: ['backend'], target: 'deploy', params: 'forward' }] },
|
|
1734
1756
|
};
|
|
1735
1757
|
try {
|
|
1736
|
-
await workspace.write(
|
|
1758
|
+
await workspace.write(
|
|
1759
|
+
'packages/site/package.json',
|
|
1760
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1761
|
+
);
|
|
1737
1762
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1738
1763
|
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1739
1764
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
@@ -1790,6 +1815,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1790
1815
|
`packages/${name}/package.json`,
|
|
1791
1816
|
JSON.stringify({
|
|
1792
1817
|
name,
|
|
1818
|
+
private: true,
|
|
1793
1819
|
nx: {
|
|
1794
1820
|
targets: {
|
|
1795
1821
|
deploy: {
|
package/src/index.ts
CHANGED
|
@@ -750,6 +750,8 @@ interface PackageJson {
|
|
|
750
750
|
bin?: unknown;
|
|
751
751
|
name?: string;
|
|
752
752
|
napi?: Record<string, unknown>;
|
|
753
|
+
/** npm's own "never published" flag, which is what makes a package a deployable target rather than a library. */
|
|
754
|
+
private?: boolean;
|
|
753
755
|
scripts?: Record<string, unknown>;
|
|
754
756
|
nx?: {
|
|
755
757
|
name?: string;
|
|
@@ -782,20 +784,22 @@ function packageBinOutputs(packageJson: PackageJson, packageJsonPath: string): s
|
|
|
782
784
|
|
|
783
785
|
/**
|
|
784
786
|
* The deployment manifests wrangler itself looks for, in its own precedence
|
|
785
|
-
* order. Finding one
|
|
786
|
-
*
|
|
787
|
+
* order. Finding one is HALF the detection: a published library ships one to
|
|
788
|
+
* document a Durable Object binding for its consumers, and that manifest is
|
|
789
|
+
* structurally indistinguishable from a deployable worker's — same `name`,
|
|
790
|
+
* `main` and `compatibility_date`. So presence alone cannot mean deployable,
|
|
791
|
+
* and the other half is `private: true` below.
|
|
787
792
|
*
|
|
788
793
|
* Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
|
|
789
794
|
* belongs to the CLI, which reads it to decide which secrets a stage requires; a
|
|
790
795
|
* second copy in the graph would disagree the first time a stage was added. And
|
|
791
|
-
* which stages CI actually runs is the four-way vocabulary in the CLI's
|
|
796
|
+
* which stages CI actually runs is the four-way tag vocabulary in the CLI's
|
|
792
797
|
* `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
|
|
793
|
-
* that a flag here could express exactly one of. So
|
|
794
|
-
* the target, and
|
|
798
|
+
* that a flag here could express exactly one of. So a private wrangler project
|
|
799
|
+
* gets the target, and the tags alone decide what CI deploys.
|
|
795
800
|
*
|
|
796
801
|
* A worker deployed by some other mechanism declares its own `options.command`,
|
|
797
|
-
* which replaces this one;
|
|
798
|
-
* it, because the `deploy-stage` string went with it.
|
|
802
|
+
* which replaces this one; the tag is what CI reads either way.
|
|
799
803
|
*/
|
|
800
804
|
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
801
805
|
|
|
@@ -805,11 +809,10 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
|
|
|
805
809
|
* `configurations` map cannot describe the surface that actually exists, and a
|
|
806
810
|
* project carrying both spellings would have two ways to say one thing.
|
|
807
811
|
*
|
|
808
|
-
* No `stage-deploy-target` tag either, deliberately: the
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
* answers, and the two would drift the first time either moved.
|
|
812
|
+
* No `stage-deploy-target` tag either, deliberately: that tag is the repository's
|
|
813
|
+
* statement that CI deploys this project on every stage, and only the repository
|
|
814
|
+
* can make it. A plugin that tagged what it inferred would enrol every private
|
|
815
|
+
* wrangler project in CI deploys by writing the policy it is supposed to read.
|
|
813
816
|
*
|
|
814
817
|
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
815
818
|
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
@@ -884,7 +887,8 @@ async function createProjectTargets(
|
|
|
884
887
|
const hasOrdinaryBuildOutputTarget =
|
|
885
888
|
hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
886
889
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
887
|
-
const
|
|
890
|
+
const isDeployableWranglerProject =
|
|
891
|
+
packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
888
892
|
|
|
889
893
|
if (hasLibTsconfig) {
|
|
890
894
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
@@ -1436,16 +1440,19 @@ async function createProjectTargets(
|
|
|
1436
1440
|
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
|
|
1437
1441
|
// measured, not assumed, against an inferred base.
|
|
1438
1442
|
//
|
|
1439
|
-
// `deploy` is INFERRED for a wrangler project rather than patched onto a hand-written
|
|
1440
|
-
// command is a constant of the convention, not of the project: every consumer wrote
|
|
1441
|
-
// `nx:run-commands` wrapper around it
|
|
1442
|
-
// a
|
|
1443
|
-
//
|
|
1444
|
-
//
|
|
1443
|
+
// `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
|
|
1444
|
+
// one. The command is a constant of the convention, not of the project: every consumer wrote
|
|
1445
|
+
// the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
|
|
1446
|
+
// detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
|
|
1447
|
+
// so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
|
|
1448
|
+
// one `nx run-many -t deploy` away. A published package that really is deployed declares
|
|
1449
|
+
// `deploy` itself. `deploy-build` stays declaration-driven in the other direction, because
|
|
1450
|
+
// only the project knows what building it means — the plugin supplies its POLICY (cache
|
|
1451
|
+
// honestly) and nothing else.
|
|
1445
1452
|
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
1446
1453
|
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
1447
1454
|
}
|
|
1448
|
-
if (
|
|
1455
|
+
if (isDeployableWranglerProject) {
|
|
1449
1456
|
// Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
|
|
1450
1457
|
// target the project lacks — measured, the task just runs alone — and a wrangler worker can
|
|
1451
1458
|
// legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
|
|
@@ -1946,6 +1953,7 @@ async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
|
|
|
1946
1953
|
...('bin' in parsed ? { bin: parsed.bin } : {}),
|
|
1947
1954
|
...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
|
|
1948
1955
|
...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
|
|
1956
|
+
...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
|
|
1949
1957
|
...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
|
|
1950
1958
|
...(rawNx
|
|
1951
1959
|
? {
|