@widgetic/dev-tools 0.3.9 → 0.3.10
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 +3 -0
- package/README.md +2 -2
- package/bin/publish-package.mjs +44 -4
- package/lib/publish-to-npm.mjs +3 -1
- package/package.json +1 -1
- package/test/publish-to-npm.test.mjs +193 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,7 @@ reasons matter more than the categories.
|
|
|
7
7
|
|
|
8
8
|
### Added
|
|
9
9
|
|
|
10
|
+
- **`@widgetic/cli` is a package of the walk.** `cli` is in `PUBLISHABLE_PACKAGES` (last: nothing bundles or loads it, and its release gate wants the contracts package the gateway publishes) and the publisher has a branch of its own for it (`packageName === 'cli'`, so it needs no sibling-layout entry: no app aliases its source). Before the version is raised it runs `npm run check` and `npm run check:release`, the gate that the commands the CLI was generated from (`@widgetic/api-contracts`) are the newest the gateway published and that production's MCP server still has the tools they describe (the gate learns that from a public document of the MCP host, with no key; a Widgetic API key made with full access is only the way for a gateway that does not publish the document yet). The gate runs in the publisher and not as `prepublishOnly` because the publish passes `--ignore-scripts`. Then it builds, publishes (public), commits the version files, tags and pushes like the other packages. `test/publish-to-npm.test.mjs` pins the order in the source and runs the real publisher in a throwaway checkout with a stand-in `npm`: a failing check and a failing gate each stop it before the version changes, and no other package runs the gate.
|
|
10
11
|
- **`publish-package.mjs`** (`bin/publish-package.mjs`): the laptop publish for every package. Each package's `publish-to-npm` script only calls this file. It does nothing when the latest commit already wrote the current version. Otherwise it raises the patch, publishes, commits the version files, tags the commit `v` plus the version, and pushes both. ui-sdk also releases the modules, and the tag is pushed after that release. embed-sdk also uploads its CDN file. dev-tools runs its tests before the version changes.
|
|
11
12
|
- **`publish-all-to-npm`** (`bin/publish-all-to-npm.mjs`): walks the npm packages and runs each package's `publish-to-npm` script.
|
|
12
13
|
- The README contract no longer checks `recorder` or `__template__`. The linking tier is `embed-sdk` and `ui-sdk`. The adopter tier is the apps that compile sibling source.
|
|
@@ -17,6 +18,8 @@ reasons matter more than the categories.
|
|
|
17
18
|
|
|
18
19
|
### Changed
|
|
19
20
|
|
|
21
|
+
- **`publish-package.mjs` checks the CDN settings before it raises the version of `ui-sdk`.** The publish of `ui-sdk` puts the package on npm and then releases the modules to the CDN, and the R2 settings that release needs are read from Doppler (the API gateway's production config) every time, with no `modules/.env`. A Doppler that was not logged in used to show only after `npm publish`, which left a version on npm with no modules to go with it. The publisher now runs `npm run release:settings` in `modules/` first (it reads the settings and one object from the bucket, writes nothing and prints no key) and stops there when it fails. `test/publish-to-npm.test.mjs` pins the order in the source and runs the real publisher in a throwaway checkout with stand-in `npm` and `node`, for `ui-sdk` and for another package.
|
|
22
|
+
- **`publish-package.mjs` checks the CDN settings before it raises the version of `embed-sdk`, and the upload takes no settings file.** The publish of `embed-sdk` puts the package on npm and then uploads its two CDN files, with the R2 settings read from `.env.cdn`, a file nobody kept in step with the gateway's. They are now read from Doppler (the API gateway's production config) every time, the way the modules' are, and embed-sdk has `npm run publish:cdn:settings` for it: it reads the six settings (the Cloudflare token and zone, for the purge, included), sends one HEAD for the SDK's object to the bucket, writes nothing and prints no key. The publisher runs it with `--purge` first and stops there when it fails, so a Doppler that was not logged in no longer shows only after `npm publish`, which left a version on npm while the CDN served the old file. The upload command no longer passes `--env-file .env.cdn` (embed-sdk's `publish:cdn` now refuses that option and says what replaced it). `test/publish-to-npm.test.mjs` pins the order in the source and runs the real publisher in a throwaway checkout with stand-in `npm` and `node`, for `embed-sdk`, and holds out the old option.
|
|
20
23
|
- **The license is the Widgetic Integration License** (`LICENSE`, and `SEE LICENSE IN LICENSE` in `package.json`), not MIT: a partner may use the package to integrate Widgetic, and for nothing else. A version published before this change stays under the license it was published with.
|
|
21
24
|
|
|
22
25
|
## 0.3.1 — 2026-10-08
|
package/README.md
CHANGED
|
@@ -399,7 +399,7 @@ laptop.
|
|
|
399
399
|
|
|
400
400
|
GitLab CI on `main` remains the way a package is published. When the group has no compute minutes left, the same publish can be done from this checkout.
|
|
401
401
|
|
|
402
|
-
`bin/publish-package.mjs` is the publish for every package. Each package's `publish-to-npm` script only calls that file. It does nothing when the latest commit is the one that wrote the current `package.json` version. When a later commit exists, it raises the patch, publishes that version, commits the version files, tags that commit `v` plus the version, and pushes the commit and the tag. The token is the one in `~/.npmrc`. For ui-sdk it also keeps `SDK_VERSION` in step, then raises the modules patch and writes one changelog sentence. It commits before the modules release, because that release refuses a dirty `modules/` directory, and tags and pushes after the release. The R2 settings for the modules are in `modules
|
|
402
|
+
`bin/publish-package.mjs` is the publish for every package. Each package's `publish-to-npm` script only calls that file. It does nothing when the latest commit is the one that wrote the current `package.json` version. When a later commit exists, it raises the patch, publishes that version, commits the version files, tags that commit `v` plus the version, and pushes the commit and the tag. The token is the one in `~/.npmrc`. For ui-sdk it also keeps `SDK_VERSION` in step, then raises the modules patch and writes one changelog sentence. It commits before the modules release, because that release refuses a dirty `modules/` directory, and tags and pushes after the release. The R2 settings for the modules are read from Doppler (the API gateway's production config) every time, so there is no file for them. Before it raises the version it runs `npm run release:settings` in `modules/`, which reads those settings and one object from the bucket and writes nothing, and the publish stops there when that fails: a package that is on npm with no modules to go with it is a half-done release. For embed-sdk it also uploads `dist/umd/embed-sdk-workflows.js` and `dist/umd/embed-sdk.js` to the CDN and purges them, then commits the version and `dist/`, tags, and pushes. The R2 settings for that upload are read from Doppler the same way, every time (there is no `.env.cdn` and no `--env-file`), and before the version is raised it runs `npm run publish:cdn:settings -- --purge` in embed-sdk, which reads the six settings and sends one HEAD for the SDK's object to the bucket, writes nothing, and stops the publish there when it fails, for the same reason. The other packages have no CDN file. dev-tools runs its tests before the version changes. `cli` (`@widgetic/cli`, the `widgetic` command) runs `npm run check` and then `npm run check:release` before the version changes, builds, publishes, and commits, tags and pushes the way the others do. Every command of the CLI is generated from `@widgetic/api-contracts`, the package the API gateway publishes, so `check:release` is the gate that the contracts it was generated from are the newest published and that production's MCP server still has the tools they describe (it reads that from the document production's MCP host publishes for it, public, with no key; only while production runs a gateway older than the release that adds the document does it ask the MCP server itself, with a Widgetic API key made with full access, from `WIDGETIC_API_KEY` or from the one `widgetic auth login` saved: the MCP endpoint refuses a key limited to some scopes, a read-only one included). It runs here, and not as the package's `prepublishOnly`, because the publish passes `--ignore-scripts`.
|
|
403
403
|
|
|
404
404
|
From one package, publish only that package:
|
|
405
405
|
|
|
@@ -413,7 +413,7 @@ From `dev-tools`, walk every package:
|
|
|
413
413
|
npm run publish-all-to-npm
|
|
414
414
|
```
|
|
415
415
|
|
|
416
|
-
The walk is `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `canvas`, `chat`, `editor`, `file-browser`, `widget-creator`, `workflows-engine`, `workflows`, `embed-sdk` and `
|
|
416
|
+
The walk is `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `canvas`, `chat`, `editor`, `file-browser`, `widget-creator`, `workflows-engine`, `workflows`, `embed-sdk`, `ui-sdk` and `cli`. `site` is not in it. These are the npm packages. The API SDK for Python, Ruby, C#, Java, PHP and Go is published from `api-gateway-service` with `scripts/publish-public-sdks.sh`, not by this walk.
|
|
417
417
|
|
|
418
418
|
## Releasing
|
|
419
419
|
|
package/bin/publish-package.mjs
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
* Publish the package in the current directory.
|
|
4
4
|
*
|
|
5
5
|
* Each package's publish-to-npm script is only this file. embed-sdk also
|
|
6
|
-
* uploads its CDN file
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* uploads its CDN file, and ui-sdk also releases the modules: each first checks,
|
|
7
|
+
* before the version changes, that it can reach the CDN's bucket with the R2
|
|
8
|
+
* settings it reads from Doppler. dev-tools runs its tests before the version
|
|
9
|
+
* changes. cli runs its checks and its release gate (the contracts it was
|
|
10
|
+
* generated from are the newest the gateway published, and production's MCP
|
|
11
|
+
* server still has the tools it was generated from, which it learns from a
|
|
12
|
+
* public document, with no key) before the version changes.
|
|
13
|
+
* Every other package builds, or packages, then publishes.
|
|
9
14
|
*
|
|
10
15
|
* The script fetches origin first. When that branch has commits this checkout
|
|
11
16
|
* does not, it merges them. A conflict stops the publish. It does nothing when
|
|
@@ -161,6 +166,32 @@ if (packageName === 'dev-tools') {
|
|
|
161
166
|
run('npm', ['test']);
|
|
162
167
|
}
|
|
163
168
|
|
|
169
|
+
if (packageName === 'cli') {
|
|
170
|
+
// Every command of the CLI is generated from @widgetic/api-contracts, so a release is only as good as the contracts it
|
|
171
|
+
// was generated from: `check:release` stops here when they are not the newest the gateway published, or when
|
|
172
|
+
// production's MCP server no longer has the tools they describe. It reads that from the document production's MCP
|
|
173
|
+
// host publishes for it (public: no key). Only while production runs a gateway older than the release that adds the
|
|
174
|
+
// document does it ask the MCP server itself, and that needs a Widgetic API key made with full access (the MCP endpoint
|
|
175
|
+
// refuses a key limited to some scopes, a read-only one included): WIDGETIC_API_KEY, or the one `widgetic auth login`
|
|
176
|
+
// saved.
|
|
177
|
+
// It runs here and not as `prepublishOnly`, because the publish below passes --ignore-scripts.
|
|
178
|
+
run('npm', ['run', 'check']);
|
|
179
|
+
run('npm', ['run', 'check:release']);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (packageName === 'ui-sdk') {
|
|
183
|
+
// The modules go to the CDN after the package is on npm. Know now that the R2 settings can be read (from Doppler, every
|
|
184
|
+
// time) and that the bucket answers them: a failure after `npm publish` leaves a version on npm with no modules to go with it.
|
|
185
|
+
run('npm', ['run', 'release:settings'], { cwd: join(packageDir, 'modules') });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (packageName === 'embed-sdk') {
|
|
189
|
+
// The CDN files go up after the package is on npm. Know now that the six R2 settings (the Cloudflare token and zone
|
|
190
|
+
// for the purge too) can be read from Doppler, every time, and that the bucket answers them: a failure after
|
|
191
|
+
// `npm publish` leaves a version on npm while the CDN still serves the old file.
|
|
192
|
+
run('npm', ['run', 'publish:cdn:settings', '--', '--purge']);
|
|
193
|
+
}
|
|
194
|
+
|
|
164
195
|
run('npm', ['version', 'patch', '--no-git-tag-version']);
|
|
165
196
|
|
|
166
197
|
if (BUILD_PACKAGES.has(packageName)) {
|
|
@@ -186,11 +217,20 @@ if (BUILD_PACKAGES.has(packageName)) {
|
|
|
186
217
|
'- Record the patch that was just published to npm'
|
|
187
218
|
);
|
|
188
219
|
tagAndPush();
|
|
220
|
+
} else if (packageName === 'cli') {
|
|
221
|
+
// The build generates the commands from the installed contracts, then compiles; the package ships dist/ and generated/.
|
|
222
|
+
run('npm', ['run', 'build']);
|
|
223
|
+
publishToNpm();
|
|
224
|
+
commitVersion(
|
|
225
|
+
['package.json', 'package-lock.json'],
|
|
226
|
+
'- Record the patch that was just published to npm'
|
|
227
|
+
);
|
|
228
|
+
tagAndPush();
|
|
189
229
|
} else if (packageName === 'embed-sdk') {
|
|
190
230
|
run('npm', ['run', 'build']);
|
|
191
231
|
run('npm', ['run', 'check:no-secrets']);
|
|
192
232
|
publishToNpm();
|
|
193
|
-
run('npm', ['run', 'publish:cdn', '--', '--yes', '--purge', '--allow-dirty'
|
|
233
|
+
run('npm', ['run', 'publish:cdn', '--', '--yes', '--purge', '--allow-dirty']);
|
|
194
234
|
commitVersion(
|
|
195
235
|
['package.json', 'package-lock.json', 'dist'],
|
|
196
236
|
'- Record the patch that was just published to npm and the CDN file built from it'
|
package/lib/publish-to-npm.mjs
CHANGED
|
@@ -22,5 +22,7 @@ export const PUBLISHABLE_PACKAGES = [
|
|
|
22
22
|
{ dir: 'workflows-engine', script: 'publish-to-npm' },
|
|
23
23
|
{ dir: 'workflows', script: 'publish-to-npm' },
|
|
24
24
|
{ dir: 'embed-sdk', script: 'publish-to-npm' },
|
|
25
|
-
{ dir: 'ui-sdk', script: 'publish-to-npm' }
|
|
25
|
+
{ dir: 'ui-sdk', script: 'publish-to-npm' },
|
|
26
|
+
// Last: nothing bundles or loads the CLI, and its release gate wants the contracts package the gateway publishes.
|
|
27
|
+
{ dir: 'cli', script: 'publish-to-npm' }
|
|
26
28
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/dev-tools",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Build-time checks and dev tooling shared by the published @widgetic packages, released once so the repositories that consume them cannot drift apart. Currently: check-runtime-deps (with the fixture suite that proves it fails), the Vite sibling-$lib remap, the canonical Frontend sibling layout that builds every consumer's dev-alias tables, and check-links — the link-doctor that fails when a sibling symlink dangles, a promised dist/ file is missing, or a dead checkout name lingers, check-design-system-peers — which fails when the two design-system peers' lockfiles drift apart, and comment-console-logs — which comments out the debugging console calls of a codebase and keeps every one of them in the code.",
|
|
6
6
|
"repository": {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { test } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
5
7
|
import { fileURLToPath } from 'node:url';
|
|
6
8
|
import { PUBLISHABLE_PACKAGES } from '../lib/publish-to-npm.mjs';
|
|
7
9
|
|
|
@@ -23,7 +25,8 @@ test('the walk calls publish-to-npm in each npm package', () => {
|
|
|
23
25
|
'workflows-engine:publish-to-npm',
|
|
24
26
|
'workflows:publish-to-npm',
|
|
25
27
|
'embed-sdk:publish-to-npm',
|
|
26
|
-
'ui-sdk:publish-to-npm'
|
|
28
|
+
'ui-sdk:publish-to-npm',
|
|
29
|
+
'cli:publish-to-npm'
|
|
27
30
|
]
|
|
28
31
|
);
|
|
29
32
|
assert.equal(PUBLISHABLE_PACKAGES.some((pkg) => pkg.dir === 'site'), false);
|
|
@@ -47,3 +50,190 @@ test('each package script calls the one publisher, and the walk is separate', ()
|
|
|
47
50
|
const devTools = JSON.parse(readFileSync(resolve(FRONTEND, 'dev-tools/package.json'), 'utf8'));
|
|
48
51
|
assert.equal(devTools.scripts['publish-all-to-npm'], 'node bin/publish-all-to-npm.mjs');
|
|
49
52
|
});
|
|
53
|
+
|
|
54
|
+
// The publisher beside this test (the one above is found through the sibling layout of the Frontend folder).
|
|
55
|
+
const PUBLISHER = fileURLToPath(new URL('../bin/publish-package.mjs', import.meta.url));
|
|
56
|
+
|
|
57
|
+
test('ui-sdk and embed-sdk check the CDN settings before they raise the version, and no other package does', () => {
|
|
58
|
+
const publisher = readFileSync(PUBLISHER, 'utf8');
|
|
59
|
+
const uiSdkPreflight = "run('npm', ['run', 'release:settings'], { cwd: join(packageDir, 'modules') });";
|
|
60
|
+
const embedSdkPreflight = "run('npm', ['run', 'publish:cdn:settings', '--', '--purge']);";
|
|
61
|
+
assert.equal(publisher.split('release:settings').length - 1, 1, 'release:settings is called once');
|
|
62
|
+
assert.equal(publisher.split('publish:cdn:settings').length - 1, 1, 'publish:cdn:settings is called once');
|
|
63
|
+
assert.equal(publisher.includes(uiSdkPreflight), true);
|
|
64
|
+
assert.equal(publisher.includes(embedSdkPreflight), true);
|
|
65
|
+
// Each call sits alone in the branch of its own package, and the two branches come right before the version is raised.
|
|
66
|
+
assert.match(
|
|
67
|
+
publisher,
|
|
68
|
+
/if \(packageName === 'ui-sdk'\) \{\n(?:\t\/\/[^\n]*\n)*\trun\('npm', \['run', 'release:settings'\], \{ cwd: join\(packageDir, 'modules'\) \}\);\n\}\n\nif \(packageName === 'embed-sdk'\) \{\n(?:\t\/\/[^\n]*\n)*\trun\('npm', \['run', 'publish:cdn:settings', '--', '--purge'\]\);\n\}\n\nrun\('npm', \['version', 'patch', '--no-git-tag-version'\]\);/
|
|
69
|
+
);
|
|
70
|
+
assert.equal(publisher.indexOf('release:settings') < publisher.indexOf('publishToNpm();'), true);
|
|
71
|
+
assert.equal(publisher.indexOf('publish:cdn:settings') < publisher.indexOf('publishToNpm();'), true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('the embed-sdk upload names no settings file: its settings come from Doppler, every time', () => {
|
|
75
|
+
const publisher = readFileSync(PUBLISHER, 'utf8');
|
|
76
|
+
assert.equal(publisher.includes('--env-file'), false);
|
|
77
|
+
assert.equal(publisher.includes('.env.cdn'), false);
|
|
78
|
+
assert.equal(publisher.includes("run('npm', ['run', 'publish:cdn', '--', '--yes', '--purge', '--allow-dirty']);"), true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('the scripts the publisher runs before it raises a version exist in the package that is checked', () => {
|
|
82
|
+
// A preflight that calls a script which is not there stops every publish of that package, before anything changes.
|
|
83
|
+
const scriptsOf = (/** @type {string} */ relativePath) =>
|
|
84
|
+
JSON.parse(readFileSync(resolve(FRONTEND, relativePath), 'utf8')).scripts ?? {};
|
|
85
|
+
assert.equal(typeof scriptsOf('ui-sdk/modules/package.json')['release:settings'], 'string');
|
|
86
|
+
assert.equal(typeof scriptsOf('embed-sdk/package.json')['publish:cdn:settings'], 'string');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Runs the real publisher in a throwaway checkout of a package called `packageName`, with a stand-in `npm` and `node`
|
|
91
|
+
* first on the PATH that only write down their arguments: nothing is built, published or sent anywhere, and no Doppler
|
|
92
|
+
* is asked. `fails` is a piece of a command line that makes the stand-ins exit 1.
|
|
93
|
+
* @param {string} packageName
|
|
94
|
+
* @param {{ fails?: string }} [options]
|
|
95
|
+
*/
|
|
96
|
+
function runPublisherIn(packageName, { fails = 'no command line has this in it' } = {}) {
|
|
97
|
+
const sandbox = mkdtempSync(join(tmpdir(), 'publish-package-'));
|
|
98
|
+
try {
|
|
99
|
+
const origin = join(sandbox, 'origin.git');
|
|
100
|
+
const checkout = join(sandbox, packageName);
|
|
101
|
+
const bin = join(sandbox, 'bin');
|
|
102
|
+
const callsFile = join(sandbox, 'calls.log');
|
|
103
|
+
mkdirSync(bin);
|
|
104
|
+
for (const tool of ['npm', 'node']) {
|
|
105
|
+
writeFileSync(
|
|
106
|
+
join(bin, tool),
|
|
107
|
+
`#!/bin/sh\necho "${tool} $*" >> "$STAND_IN_CALLS"\ncase "${tool} $*" in *"$STAND_IN_FAILS"*) exit 1 ;; esac\nexit 0\n`,
|
|
108
|
+
{ mode: 0o755 }
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const git = (/** @type {string} */ cwd, /** @type {string[]} */ ...args) => {
|
|
112
|
+
const result = spawnSync('git', ['-c', 'user.name=Test', '-c', 'user.email=test@example.test', ...args], { cwd, encoding: 'utf8' });
|
|
113
|
+
assert.equal(result.status, 0, `git ${args.join(' ')}: ${result.stderr}`);
|
|
114
|
+
return result.stdout.trim();
|
|
115
|
+
};
|
|
116
|
+
git(sandbox, 'init', '--bare', '-b', 'main', origin);
|
|
117
|
+
mkdirSync(join(checkout, 'src', 'sdk'), { recursive: true });
|
|
118
|
+
mkdirSync(join(checkout, 'modules'));
|
|
119
|
+
git(checkout, 'init', '-b', 'main');
|
|
120
|
+
git(checkout, 'remote', 'add', 'origin', origin);
|
|
121
|
+
writeFileSync(join(checkout, 'package.json'), JSON.stringify({ name: packageName, version: '0.0.1' }, null, 2) + '\n');
|
|
122
|
+
writeFileSync(join(checkout, 'src', 'sdk', 'version.ts'), "export const SDK_VERSION = '0.0.1';\n");
|
|
123
|
+
git(checkout, 'add', '.');
|
|
124
|
+
git(checkout, 'commit', '-m', 'chore: publish 0.0.1');
|
|
125
|
+
writeFileSync(join(checkout, 'change.txt'), 'something that is not published yet\n');
|
|
126
|
+
git(checkout, 'add', '.');
|
|
127
|
+
git(checkout, 'commit', '-m', 'feat: a change since the last publish');
|
|
128
|
+
git(checkout, 'push', '-u', 'origin', 'main');
|
|
129
|
+
const commitsBefore = git(checkout, 'rev-list', '--count', 'HEAD');
|
|
130
|
+
|
|
131
|
+
const result = spawnSync(process.execPath, [PUBLISHER], {
|
|
132
|
+
cwd: checkout,
|
|
133
|
+
encoding: 'utf8',
|
|
134
|
+
env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, STAND_IN_CALLS: callsFile, STAND_IN_FAILS: fails }
|
|
135
|
+
});
|
|
136
|
+
const calls = existsSync(callsFile) ? readFileSync(callsFile, 'utf8').split('\n').filter(Boolean) : [];
|
|
137
|
+
return {
|
|
138
|
+
status: result.status,
|
|
139
|
+
output: `${result.stdout}${result.stderr}`,
|
|
140
|
+
calls,
|
|
141
|
+
versionInPackageJson: JSON.parse(readFileSync(join(checkout, 'package.json'), 'utf8')).version,
|
|
142
|
+
commitsAdded: Number(git(checkout, 'rev-list', '--count', 'HEAD')) - Number(commitsBefore)
|
|
143
|
+
};
|
|
144
|
+
} finally {
|
|
145
|
+
rmSync(sandbox, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
test('ui-sdk stops before it raises the version, builds or publishes anything, when the CDN settings cannot be read', () => {
|
|
150
|
+
const run = runPublisherIn('ui-sdk', { fails: 'run release:settings' });
|
|
151
|
+
assert.equal(run.status, 1, run.output);
|
|
152
|
+
assert.deepEqual(run.calls, ['npm run release:settings']);
|
|
153
|
+
assert.equal(run.versionInPackageJson, '0.0.1');
|
|
154
|
+
assert.equal(run.commitsAdded, 0);
|
|
155
|
+
assert.match(run.output, /ui-sdk: npm run release:settings exited 1/);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('ui-sdk checks the CDN settings first, then raises the version, then builds and publishes', () => {
|
|
159
|
+
const run = runPublisherIn('ui-sdk');
|
|
160
|
+
assert.deepEqual(run.calls.slice(0, 3), ['npm run release:settings', 'npm version patch --no-git-tag-version', 'npm run build:publish']);
|
|
161
|
+
assert.equal(run.calls.indexOf('npm run release:settings') < run.calls.findIndex((call) => call.startsWith('npm publish')), true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('embed-sdk stops before it raises the version, builds or publishes anything, when the CDN settings cannot be read', () => {
|
|
165
|
+
const run = runPublisherIn('embed-sdk', { fails: 'run publish:cdn:settings' });
|
|
166
|
+
assert.equal(run.status, 1, run.output);
|
|
167
|
+
assert.deepEqual(run.calls, ['npm run publish:cdn:settings -- --purge']);
|
|
168
|
+
assert.equal(run.versionInPackageJson, '0.0.1');
|
|
169
|
+
assert.equal(run.commitsAdded, 0);
|
|
170
|
+
assert.match(run.output, /embed-sdk: npm run publish:cdn:settings -- --purge exited 1/);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('embed-sdk checks the CDN settings first, then raises the version, builds, publishes to npm and uploads with no settings file', () => {
|
|
174
|
+
const run = runPublisherIn('embed-sdk');
|
|
175
|
+
// The stand-in `npm` changes no version, so the commit that follows has nothing in it: only the calls of npm and node are held here.
|
|
176
|
+
assert.deepEqual(run.calls, [
|
|
177
|
+
'npm run publish:cdn:settings -- --purge',
|
|
178
|
+
'npm version patch --no-git-tag-version',
|
|
179
|
+
'npm run build',
|
|
180
|
+
'npm run check:no-secrets',
|
|
181
|
+
'npm publish --ignore-scripts --access public',
|
|
182
|
+
'npm run publish:cdn -- --yes --purge --allow-dirty'
|
|
183
|
+
]);
|
|
184
|
+
for (const call of run.calls) assert.doesNotMatch(call, /--env-file|\.env\.cdn/);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('the cli runs its checks and its release gate before the version is raised, and no other package runs the gate', () => {
|
|
188
|
+
const publisher = readFileSync(PUBLISHER, 'utf8');
|
|
189
|
+
const gateCall = "run('npm', ['run', 'check:release']);";
|
|
190
|
+
assert.equal(publisher.split(gateCall).length - 1, 1, 'check:release is called once');
|
|
191
|
+
assert.match(
|
|
192
|
+
publisher,
|
|
193
|
+
/if \(packageName === 'cli'\) \{\n(?:\t\/\/[^\n]*\n)*\trun\('npm', \['run', 'check'\]\);\n\trun\('npm', \['run', 'check:release'\]\);\n\}\n\nif \(packageName === 'ui-sdk'\) \{/
|
|
194
|
+
);
|
|
195
|
+
// The gate is not `prepublishOnly`: the publish passes --ignore-scripts, so a script of the package would be skipped.
|
|
196
|
+
assert.equal(publisher.indexOf(gateCall) < publisher.indexOf("run('npm', ['version', 'patch'"), true);
|
|
197
|
+
assert.equal(publisher.indexOf(gateCall) < publisher.indexOf('publishToNpm();'), true);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('the cli stops before it raises the version, builds or publishes anything, when its own checks fail', () => {
|
|
201
|
+
const run = runPublisherIn('cli', { fails: 'run check' });
|
|
202
|
+
assert.equal(run.status, 1, run.output);
|
|
203
|
+
assert.deepEqual(run.calls, ['npm run check']);
|
|
204
|
+
assert.equal(run.versionInPackageJson, '0.0.1');
|
|
205
|
+
assert.equal(run.commitsAdded, 0);
|
|
206
|
+
assert.match(run.output, /cli: npm run check exited 1/);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('the cli stops before it raises the version, builds or publishes anything, when the release gate fails', () => {
|
|
210
|
+
const run = runPublisherIn('cli', { fails: 'run check:release' });
|
|
211
|
+
assert.equal(run.status, 1, run.output);
|
|
212
|
+
assert.deepEqual(run.calls, ['npm run check', 'npm run check:release']);
|
|
213
|
+
assert.equal(run.versionInPackageJson, '0.0.1');
|
|
214
|
+
assert.equal(run.commitsAdded, 0);
|
|
215
|
+
assert.match(run.output, /cli: npm run check:release exited 1/);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('the cli checks, gates, raises the version, builds and publishes to npm, in that order and nothing else', () => {
|
|
219
|
+
const run = runPublisherIn('cli');
|
|
220
|
+
// The stand-in `npm` changes no version, so the commit that follows has nothing in it: only the calls of npm are held here.
|
|
221
|
+
assert.deepEqual(run.calls, [
|
|
222
|
+
'npm run check',
|
|
223
|
+
'npm run check:release',
|
|
224
|
+
'npm version patch --no-git-tag-version',
|
|
225
|
+
'npm run build',
|
|
226
|
+
'npm publish --ignore-scripts --access public'
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('another package does not run the release gate of the cli', () => {
|
|
231
|
+
const run = runPublisherIn('canvas');
|
|
232
|
+
assert.equal(run.calls.some((call) => call.includes('check:release')), false);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('another package does not check the CDN settings', () => {
|
|
236
|
+
const run = runPublisherIn('canvas');
|
|
237
|
+
assert.equal(run.calls.some((call) => call.includes('release:settings') || call.includes('publish:cdn:settings')), false);
|
|
238
|
+
assert.equal(run.calls[0], 'npm version patch --no-git-tag-version');
|
|
239
|
+
});
|