codeplay-common 4.11.37 → 4.11.39
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 +29 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +2 -2
- package/files/buildCodeplay/ensure-current-build.cjs +70 -42
- package/files/scripts-common/collect-startup-profile.js +134 -0
- package/files/scripts-common/generate-baseline-profile.js +218 -46
- package/files/take-screen-image.js +103 -64
- package/package.json +1 -1
- package/scripts/baseline-profile.test.cjs +189 -0
- package/scripts/ensure-current-build.test.cjs +176 -76
|
@@ -1,76 +1,176 @@
|
|
|
1
|
-
const { test } = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
-
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
fs.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
assert.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const vm = require('node:vm');
|
|
6
|
+
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
+
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
+
|
|
9
|
+
function installPackage(root) {
|
|
10
|
+
const directory = path.join(root, 'node_modules', 'codeplay-common');
|
|
11
|
+
fs.mkdirSync(path.join(directory, 'scripts'), { recursive: true });
|
|
12
|
+
fs.writeFileSync(path.join(directory, 'package.json'), JSON.stringify({ name: 'codeplay-common', version: '4.11.38' }));
|
|
13
|
+
fs.writeFileSync(path.join(directory, 'scripts', 'sync-files.js'), '');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fixture(t, names = [], options = {}) {
|
|
17
|
+
const temporaryRoot = path.resolve(__dirname, '../agent-temp/ensure-current-build-tests');
|
|
18
|
+
fs.mkdirSync(temporaryRoot, { recursive: true });
|
|
19
|
+
const root = fs.mkdtempSync(path.join(temporaryRoot, 'app-'));
|
|
20
|
+
t.after(() => {
|
|
21
|
+
assert.equal(path.dirname(path.resolve(root)), temporaryRoot);
|
|
22
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
23
|
+
});
|
|
24
|
+
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
25
|
+
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
26
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'test-app', ...options.manifest }));
|
|
27
|
+
if (options.installed !== false) installPackage(root);
|
|
28
|
+
return root;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test('healthy current structure continues without npm or installer commands', t => {
|
|
32
|
+
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
33
|
+
assert.equal(ensureCurrentBuild({
|
|
34
|
+
projectRoot,
|
|
35
|
+
runNpm: () => assert.fail('unexpected npm command'),
|
|
36
|
+
runInstaller: () => assert.fail('unexpected installer command'),
|
|
37
|
+
runBeforeBuild: () => assert.fail('unexpected restart'),
|
|
38
|
+
}), false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('legacy files migrate even when npm skips lifecycle scripts for an unchanged package', t => {
|
|
42
|
+
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
43
|
+
const calls = [];
|
|
44
|
+
assert.equal(ensureCurrentBuild({
|
|
45
|
+
projectRoot,
|
|
46
|
+
runNpm: command => calls.push(command),
|
|
47
|
+
runInstaller(script) {
|
|
48
|
+
assert.equal(script, path.join(projectRoot, 'node_modules/codeplay-common/scripts/sync-files.js'));
|
|
49
|
+
calls.push('installer');
|
|
50
|
+
removeVersionedBuildScripts(projectRoot);
|
|
51
|
+
},
|
|
52
|
+
runBeforeBuild(script) {
|
|
53
|
+
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
54
|
+
calls.push('fresh preparation');
|
|
55
|
+
},
|
|
56
|
+
}), true);
|
|
57
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'installer', 'fresh preparation']);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('interrupted uninstall with no dependency declaration is recovered before preparation', t => {
|
|
61
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
62
|
+
const calls = [];
|
|
63
|
+
assert.equal(ensureCurrentBuild({
|
|
64
|
+
projectRoot,
|
|
65
|
+
runNpm(command) { calls.push(command); installPackage(projectRoot); },
|
|
66
|
+
runBeforeBuild() {
|
|
67
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules/codeplay-common/package.json'))).version, '4.11.38');
|
|
68
|
+
calls.push('fresh preparation');
|
|
69
|
+
},
|
|
70
|
+
}), true);
|
|
71
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'fresh preparation']);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
for (const manifest of [
|
|
75
|
+
{ dependencies: { 'codeplay-common': '^4.11.38' } },
|
|
76
|
+
{ devDependencies: { 'codeplay-common': 'file:../common-source' } },
|
|
77
|
+
{ optionalDependencies: { 'codeplay-common': '4.11.38' } },
|
|
78
|
+
]) {
|
|
79
|
+
test(`recovery preserves declared ${Object.keys(manifest)[0]} specification`, t => {
|
|
80
|
+
const projectRoot = fixture(t, [], { installed: false, manifest });
|
|
81
|
+
const packagePath = path.join(projectRoot, 'package.json');
|
|
82
|
+
const original = fs.readFileSync(packagePath, 'utf8');
|
|
83
|
+
assert.equal(ensureCurrentBuild({
|
|
84
|
+
projectRoot,
|
|
85
|
+
runNpm(command) { assert.equal(command, 'npm install'); installPackage(projectRoot); },
|
|
86
|
+
runBeforeBuild() {},
|
|
87
|
+
}), true);
|
|
88
|
+
assert.equal(fs.readFileSync(packagePath, 'utf8'), original);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const incompleteFile of ['package.json', 'scripts/sync-files.js']) {
|
|
93
|
+
test(`incomplete package with damaged ${incompleteFile} is repaired`, t => {
|
|
94
|
+
const projectRoot = fixture(t);
|
|
95
|
+
const file = path.join(projectRoot, 'node_modules/codeplay-common', incompleteFile);
|
|
96
|
+
if (incompleteFile === 'package.json') fs.writeFileSync(file, '{');
|
|
97
|
+
else fs.unlinkSync(file);
|
|
98
|
+
let installs = 0;
|
|
99
|
+
assert.equal(ensureCurrentBuild({
|
|
100
|
+
projectRoot,
|
|
101
|
+
runNpm() { installs++; installPackage(projectRoot); },
|
|
102
|
+
runBeforeBuild() {},
|
|
103
|
+
}), true);
|
|
104
|
+
assert.equal(installs, 1);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test('npm failure stops before running refreshed preparation', t => {
|
|
109
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
110
|
+
assert.throws(() => ensureCurrentBuild({
|
|
111
|
+
projectRoot,
|
|
112
|
+
runNpm() { throw Object.assign(new Error('npm failed'), { status: 9 }); },
|
|
113
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
114
|
+
}), { message: 'npm failed', status: 9 });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('incomplete recovery stops without restarting or retrying indefinitely', t => {
|
|
118
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
119
|
+
let installs = 0;
|
|
120
|
+
assert.throws(() => ensureCurrentBuild({
|
|
121
|
+
projectRoot,
|
|
122
|
+
runNpm() { installs++; },
|
|
123
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
124
|
+
}), /still missing or incomplete after npm install/);
|
|
125
|
+
assert.equal(installs, 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('installer failure stops preparation', t => {
|
|
129
|
+
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
130
|
+
assert.throws(() => ensureCurrentBuild({
|
|
131
|
+
projectRoot,
|
|
132
|
+
runNpm() {},
|
|
133
|
+
runInstaller() { throw new Error('migration failed'); },
|
|
134
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
135
|
+
}), /migration failed/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('unknown versioned files stop without deleting app files or looping', t => {
|
|
139
|
+
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
140
|
+
const calls = [];
|
|
141
|
+
assert.throws(() => ensureCurrentBuild({
|
|
142
|
+
projectRoot,
|
|
143
|
+
runNpm: command => calls.push(command),
|
|
144
|
+
runInstaller() { calls.push('installer'); removeVersionedBuildScripts(projectRoot); },
|
|
145
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
146
|
+
}), /Legacy buildCodeplay files remain/);
|
|
147
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'installer']);
|
|
148
|
+
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('failed refreshed preparation propagates to stop the build', t => {
|
|
152
|
+
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
153
|
+
assert.throws(() => ensureCurrentBuild({
|
|
154
|
+
projectRoot,
|
|
155
|
+
runNpm() { removeVersionedBuildScripts(projectRoot); },
|
|
156
|
+
runInstaller: () => assert.fail('npm already migrated the templates'),
|
|
157
|
+
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
158
|
+
}), { message: 'preparation failed', status: 7 });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('normal version update installs directly without removing the working dependency', () => {
|
|
162
|
+
const source = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
|
|
163
|
+
const functionSource = source.slice(source.indexOf('function checkPackageVersion()'), source.indexOf('// Run package version check'));
|
|
164
|
+
const calls = [];
|
|
165
|
+
vm.runInNewContext(`${functionSource}\ncheckPackageVersion();`, {
|
|
166
|
+
fs: { readFileSync: () => JSON.stringify({ dependencies: { 'codeplay-common': '^4.11.37' } }) },
|
|
167
|
+
packageJsonPath: 'package.json',
|
|
168
|
+
getInstalledVersion: () => '4.11.37',
|
|
169
|
+
getLatestVersion: () => '4.11.38',
|
|
170
|
+
compareVersionStrings: () => -1,
|
|
171
|
+
execSync: command => calls.push(command),
|
|
172
|
+
console: { log() {}, error() {} },
|
|
173
|
+
process: { exit: () => assert.fail('must not exit') },
|
|
174
|
+
});
|
|
175
|
+
assert.deepEqual(calls, ['npm install codeplay-common']);
|
|
176
|
+
});
|