@widgetic/dev-tools 0.3.3 → 0.3.4
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 +2 -1
- package/README.md +1 -1
- package/bin/publish-all-to-npm.mjs +2 -3
- package/bin/publish-package.mjs +176 -0
- package/lib/publish-to-npm.mjs +3 -3
- package/package.json +2 -2
- package/test/publish-to-npm.test.mjs +11 -13
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,8 @@ reasons matter more than the categories.
|
|
|
7
7
|
|
|
8
8
|
### Added
|
|
9
9
|
|
|
10
|
-
- **`publish-
|
|
10
|
+
- **`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
|
+
- **`publish-all-to-npm`** (`bin/publish-all-to-npm.mjs`): walks the npm packages and runs each package's `publish-to-npm` script.
|
|
11
12
|
- 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.
|
|
12
13
|
|
|
13
14
|
## 0.3.1 — 2026-10-08
|
package/README.md
CHANGED
|
@@ -323,7 +323,7 @@ no longer make.
|
|
|
323
323
|
|
|
324
324
|
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.
|
|
325
325
|
|
|
326
|
-
Each package's `publish-to-npm` script
|
|
326
|
+
`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/.env`, which is not committed. For embed-sdk it also uploads `dist/umd/embed-sdk.js` to the CDN and purges it, then commits the version and `dist/`, tags, and pushes. The R2 settings for that upload are in `.env.cdn`, which is not committed. The other packages have no CDN file. dev-tools runs its tests before the version changes.
|
|
327
327
|
|
|
328
328
|
From one package, publish only that package:
|
|
329
329
|
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* npm run publish-all-to-npm
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* embed-sdk also uploads its CDN file. This file only walks the checkouts.
|
|
7
|
+
* Each package.json calls bin/publish-package.mjs. That file is the publish.
|
|
8
|
+
* This file only walks the checkouts.
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
import { spawnSync } from 'node:child_process';
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Publish the package in the current directory.
|
|
4
|
+
*
|
|
5
|
+
* Each package's publish-to-npm script is only this file. embed-sdk also
|
|
6
|
+
* uploads its CDN file. ui-sdk also releases the modules. dev-tools runs its
|
|
7
|
+
* tests before the version changes. Every other package builds, or packages,
|
|
8
|
+
* then publishes.
|
|
9
|
+
*
|
|
10
|
+
* The script does nothing when the latest commit is the one that wrote the
|
|
11
|
+
* current package.json version. Otherwise it raises the patch, publishes,
|
|
12
|
+
* commits the version files, tags that commit v plus the version, and pushes
|
|
13
|
+
* the commit and the tag.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { spawnSync } from 'node:child_process';
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { basename, join } from 'node:path';
|
|
19
|
+
|
|
20
|
+
const packageDir = process.cwd();
|
|
21
|
+
const packageName = basename(packageDir);
|
|
22
|
+
|
|
23
|
+
const BUILD_PACKAGES = new Set(['api-sdk', 'cache-layer', 'design-system']);
|
|
24
|
+
const PACKAGE_PACKAGES = new Set(['canvas', 'chat', 'editor', 'file-browser', 'widget-creator']);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Run a command and stop the publish when it fails.
|
|
28
|
+
* @param {string} command
|
|
29
|
+
* @param {string[]} args
|
|
30
|
+
* @param {{ cwd?: string, env?: NodeJS.ProcessEnv }} [options]
|
|
31
|
+
*/
|
|
32
|
+
function run(command, args, options = {}) {
|
|
33
|
+
const result = spawnSync(command, args, {
|
|
34
|
+
cwd: options.cwd ?? packageDir,
|
|
35
|
+
env: options.env ?? process.env,
|
|
36
|
+
stdio: 'inherit'
|
|
37
|
+
});
|
|
38
|
+
if (result.status !== 0) {
|
|
39
|
+
console.error(`[publish-package] ${packageName}: ${command} ${args.join(' ')} exited ${result.status ?? 'without a status'}`);
|
|
40
|
+
process.exit(result.status ?? 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {string[]} args
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
function gitOutput(args) {
|
|
49
|
+
return spawnSync('git', args, { cwd: packageDir, encoding: 'utf8' }).stdout.trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @returns {string} */
|
|
53
|
+
function readVersion() {
|
|
54
|
+
return JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8')).version;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The latest commit is the one that introduced this version string, so there
|
|
59
|
+
* is nothing new to publish.
|
|
60
|
+
* @param {string} version
|
|
61
|
+
* @returns {boolean}
|
|
62
|
+
*/
|
|
63
|
+
function versionCommitIsHead(version) {
|
|
64
|
+
const versionCommit = gitOutput(['log', '-1', '--format=%H', '-S', `"version": "${version}"`, '--', 'package.json']);
|
|
65
|
+
const head = gitOutput(['rev-parse', 'HEAD']);
|
|
66
|
+
return versionCommit !== '' && versionCommit === head;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {string[]} paths
|
|
71
|
+
* @param {string} detail
|
|
72
|
+
*/
|
|
73
|
+
function commitVersion(paths, detail) {
|
|
74
|
+
const version = readVersion();
|
|
75
|
+
const present = paths.filter((path) => existsSync(join(packageDir, path)));
|
|
76
|
+
run('git', ['add', '--', ...present]);
|
|
77
|
+
run('git', ['commit', '-m', `chore: publish ${version}`, '-m', detail]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function tagAndPush() {
|
|
81
|
+
const version = readVersion();
|
|
82
|
+
const tag = `v${version}`;
|
|
83
|
+
console.log(`[publish-package] ${packageName}: tagging ${tag}`);
|
|
84
|
+
run('git', ['tag', '-a', tag, '-m', tag]);
|
|
85
|
+
run('git', ['push', 'origin', 'HEAD', tag]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function publishToNpm() {
|
|
89
|
+
run('npm', ['publish', '--ignore-scripts', '--access', 'public']);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const currentVersion = readVersion();
|
|
93
|
+
if (versionCommitIsHead(currentVersion)) {
|
|
94
|
+
console.log(`[publish-package] ${packageName}: no commits since ${currentVersion}. Nothing to publish.`);
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log(`[publish-package] ${packageName}: publishing the next patch after ${currentVersion}`);
|
|
99
|
+
|
|
100
|
+
if (packageName === 'dev-tools') {
|
|
101
|
+
run('npm', ['test']);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
run('npm', ['version', 'patch', '--no-git-tag-version']);
|
|
105
|
+
|
|
106
|
+
if (BUILD_PACKAGES.has(packageName)) {
|
|
107
|
+
run('npm', ['run', 'build']);
|
|
108
|
+
publishToNpm();
|
|
109
|
+
commitVersion(
|
|
110
|
+
['package.json', 'package-lock.json'],
|
|
111
|
+
'- Record the patch that was just published to npm'
|
|
112
|
+
);
|
|
113
|
+
tagAndPush();
|
|
114
|
+
} else if (PACKAGE_PACKAGES.has(packageName)) {
|
|
115
|
+
run('npm', ['run', 'package']);
|
|
116
|
+
publishToNpm();
|
|
117
|
+
commitVersion(
|
|
118
|
+
['package.json', 'package-lock.json'],
|
|
119
|
+
'- Record the patch that was just published to npm'
|
|
120
|
+
);
|
|
121
|
+
tagAndPush();
|
|
122
|
+
} else if (packageName === 'dev-tools') {
|
|
123
|
+
publishToNpm();
|
|
124
|
+
commitVersion(
|
|
125
|
+
['package.json', 'package-lock.json'],
|
|
126
|
+
'- Record the patch that was just published to npm'
|
|
127
|
+
);
|
|
128
|
+
tagAndPush();
|
|
129
|
+
} else if (packageName === 'embed-sdk') {
|
|
130
|
+
run('npm', ['run', 'build']);
|
|
131
|
+
run('npm', ['run', 'check:no-secrets']);
|
|
132
|
+
publishToNpm();
|
|
133
|
+
run('npm', ['run', 'publish:cdn', '--', '--yes', '--purge', '--allow-dirty', '--env-file', '.env.cdn']);
|
|
134
|
+
commitVersion(
|
|
135
|
+
['package.json', 'package-lock.json', 'dist'],
|
|
136
|
+
'- Record the patch that was just published to npm and the CDN file built from it'
|
|
137
|
+
);
|
|
138
|
+
tagAndPush();
|
|
139
|
+
} else if (packageName === 'ui-sdk') {
|
|
140
|
+
const versionFile = join(packageDir, 'src/sdk/version.ts');
|
|
141
|
+
const version = readVersion();
|
|
142
|
+
writeFileSync(
|
|
143
|
+
versionFile,
|
|
144
|
+
readFileSync(versionFile, 'utf8').replace(/SDK_VERSION = '[^']+'/, `SDK_VERSION = '${version}'`)
|
|
145
|
+
);
|
|
146
|
+
run('npm', ['run', 'build:publish']);
|
|
147
|
+
run('node', ['scripts-sdk/check-no-secrets.js']);
|
|
148
|
+
publishToNpm();
|
|
149
|
+
run('node', ['modules/scripts/advance-module-version.mjs']);
|
|
150
|
+
commitVersion(
|
|
151
|
+
[
|
|
152
|
+
'package.json',
|
|
153
|
+
'package-lock.json',
|
|
154
|
+
'src/sdk/version.ts',
|
|
155
|
+
'modules/package.json',
|
|
156
|
+
'modules/package-lock.json',
|
|
157
|
+
'modules/src/composition-editor/CHANGELOG.md',
|
|
158
|
+
'modules/src/file-browser/CHANGELOG.md',
|
|
159
|
+
'modules/src/widget-creator/CHANGELOG.md'
|
|
160
|
+
],
|
|
161
|
+
'- Record the package patch and the modules patch that were just published'
|
|
162
|
+
);
|
|
163
|
+
const modulesDir = join(packageDir, 'modules');
|
|
164
|
+
const modulesVersion = JSON.parse(readFileSync(join(modulesDir, 'package.json'), 'utf8')).version;
|
|
165
|
+
const modulesTag = `modules-v${modulesVersion}`;
|
|
166
|
+
run('npm', ['run', 'release:check', '--', '--tag', modulesTag], { cwd: modulesDir });
|
|
167
|
+
run('npm', ['run', 'build'], {
|
|
168
|
+
cwd: modulesDir,
|
|
169
|
+
env: { ...process.env, NODE_OPTIONS: '--max-old-space-size=8192' }
|
|
170
|
+
});
|
|
171
|
+
run('npm', ['run', 'release:publish', '--', '--tag', modulesTag], { cwd: modulesDir });
|
|
172
|
+
tagAndPush();
|
|
173
|
+
} else {
|
|
174
|
+
console.error(`[publish-package] ${packageName} is not one of the packages this script publishes`);
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
package/lib/publish-to-npm.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Frontend checkouts whose `npm run publish-to-npm` publishes that package.
|
|
3
3
|
*
|
|
4
|
-
* `publish-all-to-npm`
|
|
5
|
-
*
|
|
6
|
-
* app, not a package on npm.
|
|
4
|
+
* `publish-all-to-npm` walks this list and runs that script. The script calls
|
|
5
|
+
* `bin/publish-package.mjs`, which is the publish for every package. `site`
|
|
6
|
+
* is absent because it is an app, not a package on npm.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** @typedef {{ dir: string, script: string }} PublishablePackage */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/dev-tools",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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, and check-design-system-peers — which fails when the two design-system peers' lockfiles drift apart.",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test:peers": "node --test test/lockfile-peers.test.mjs",
|
|
46
46
|
"test:publish": "node --test test/publish-to-npm.test.mjs",
|
|
47
47
|
"test": "npm run check:deps && npm run test:deps && npm run test:vite && npm run test:layout && npm run test:links && npm run test:readme && npm run test:peers && npm run test:publish",
|
|
48
|
-
"publish-to-npm": "
|
|
48
|
+
"publish-to-npm": "node bin/publish-package.mjs",
|
|
49
49
|
"publish-all-to-npm": "node bin/publish-all-to-npm.mjs",
|
|
50
50
|
"prepublishOnly": "npm test"
|
|
51
51
|
},
|
|
@@ -27,23 +27,21 @@ test('the walk calls publish-to-npm in each npm package', () => {
|
|
|
27
27
|
assert.equal(PUBLISHABLE_PACKAGES.some((pkg) => pkg.dir === 'site'), false);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
test('each package script
|
|
30
|
+
test('each package script calls the one publisher, and the walk is separate', () => {
|
|
31
|
+
const publisher = readFileSync(resolve(FRONTEND, 'dev-tools/bin/publish-package.mjs'), 'utf8');
|
|
32
|
+
assert.equal(publisher.includes('no commits since'), true);
|
|
33
|
+
assert.equal(publisher.includes("['tag', '-a', tag, '-m', tag]"), true);
|
|
34
|
+
assert.equal(publisher.includes('publish:cdn'), true);
|
|
35
|
+
assert.equal(publisher.includes('advance-module-version.mjs'), true);
|
|
36
|
+
assert.equal(publisher.indexOf('commitVersion(') < publisher.indexOf('release:publish'), true);
|
|
31
37
|
for (const pkg of PUBLISHABLE_PACKAGES) {
|
|
32
38
|
const manifest = JSON.parse(readFileSync(resolve(FRONTEND, pkg.dir, 'package.json'), 'utf8'));
|
|
33
39
|
const command = manifest.scripts?.[pkg.script];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
assert.equal(command
|
|
38
|
-
assert.equal(command.includes('git push origin HEAD'), true, `${pkg.dir} does not push the version`);
|
|
39
|
-
assert.equal(command.includes('publish-all-to-npm'), false, `${pkg.dir} script is the walk`);
|
|
40
|
+
const expected = pkg.dir === 'dev-tools'
|
|
41
|
+
? 'node bin/publish-package.mjs'
|
|
42
|
+
: 'node ../dev-tools/bin/publish-package.mjs';
|
|
43
|
+
assert.equal(command, expected, `${pkg.dir} does not call the shared publisher`);
|
|
40
44
|
}
|
|
41
|
-
const uiSdk = JSON.parse(readFileSync(resolve(FRONTEND, 'ui-sdk/package.json'), 'utf8'));
|
|
42
|
-
assert.equal(uiSdk.scripts['publish-to-npm'].indexOf('git commit') < uiSdk.scripts['publish-to-npm'].indexOf('release:publish'), true);
|
|
43
|
-
assert.equal(uiSdk.scripts['publish-to-npm'].includes('advance-module-version.mjs'), true);
|
|
44
|
-
assert.equal(uiSdk.scripts['publish-to-npm'].includes('release:publish'), true);
|
|
45
|
-
const embed = JSON.parse(readFileSync(resolve(FRONTEND, 'embed-sdk/package.json'), 'utf8'));
|
|
46
|
-
assert.equal(embed.scripts['publish-to-npm'].includes('publish:cdn'), true);
|
|
47
45
|
const devTools = JSON.parse(readFileSync(resolve(FRONTEND, 'dev-tools/package.json'), 'utf8'));
|
|
48
46
|
assert.equal(devTools.scripts['publish-all-to-npm'], 'node bin/publish-all-to-npm.mjs');
|
|
49
47
|
});
|