Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ attempts that green builds would otherwise hide:
- **Verdaccio (CLI init tests):** `verdaccio/generate-config.js` emits the config at
runtime, so the uplink targets the feed (with the CI token when present) while
local packages still publish offline. The former static `config.yaml` was removed.
Before publishing, CLI init checks for existing versions through the same local
Verdaccio registry, not the default proxy. This sees versions published directly
to the authenticated CI feed and prevents duplicate-publish conflicts.
- **React Native DevTools:** `RNDT_DEV: 1` stops DevTools from fetching its
standalone shell binary from a Facebook CDN when Metro starts. The debugger is
never opened in CI, so this has no effect on tests.
Expand Down
2 changes: 1 addition & 1 deletion .ado/templates/verdaccio-start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ steps:
- script: node .ado/scripts/npmPack.js --clean --no-color
displayName: Pack all workspace packages

- script: node .ado/scripts/npmPack.js --no-pack --check-npm --no-color
- script: node .ado/scripts/npmPack.js --no-pack --check-npm --registry http://localhost:4873 --no-color
displayName: Remove already published packages

- script: |
Expand Down
117 changes: 117 additions & 0 deletions .ado/tests/verdaccio-pruning.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const assert = require('node:assert/strict');
const {execFile, execFileSync} = require('node:child_process');
const {once} = require('node:events');
const {promises: fs} = require('node:fs');
const http = require('node:http');
const os = require('node:os');
const path = require('node:path');
const {test} = require('node:test');
const {promisify} = require('node:util');

const run = promisify(execFile);
const repoRoot = path.resolve(__dirname, '..', '..');

for (const name of ['@rnw-tests/registry-fixture', 'rnw-registry-fixture']) {
test(`Windows CLI-init prunes published ${name} versions using the publish registry, not the default proxy`, async t => {
if (process.platform !== 'win32') {
t.skip('CLI-init uses the Windows Node/npm installation layout');
return;
}

const template = await fs.readFile(
path.join(repoRoot, '.ado', 'templates', 'verdaccio-start.yml'),
'utf8',
);
const command = template.match(
/^\s*- script: node (\.ado\/scripts\/npmPack\.js[^\r\n]*--check-npm[^\r\n]*)$/m,
);
assert.ok(command, 'CLI-init must check already published packages');
const [script, ...args] = command[1].split(/\s+/);
const publishRegistry = template.match(
/npm publish "[^"]+" --registry (\S+)/,
)?.[1];
assert.ok(publishRegistry, 'CLI-init must specify its publish registry');

const root = await fs.mkdtemp(
path.join(os.tmpdir(), 'rnw-verdaccio-pruning-'),
);
t.after(() => fs.rm(root, {recursive: true, force: true}));
const packages = path.join(root, 'packages');
const userConfig = path.join(root, '.npmrc');
const globalConfig = path.join(root, '.global-npmrc');
await Promise.all([
fs.mkdir(packages),
fs.mkdir(path.join(root, 'package')),
fs.writeFile(userConfig, ''),
fs.writeFile(globalConfig, ''),
]);
for (const version of ['1.0.0', '1.0.1']) {
await fs.writeFile(
path.join(root, 'package', 'package.json'),
JSON.stringify({name, version}),
);
execFileSync('tar', [
'-czf',
path.join(packages, `${version}.tgz`),
'-C',
root,
'package',
]);
}

const requests = [];
const server = http.createServer((request, response) => {
const pathname = decodeURIComponent(
new URL(request.url, 'http://localhost').pathname,
);
requests.push(pathname);
const isPublishRegistry = pathname === `/verdaccio/${name}`;
response.writeHead(isPublishRegistry ? 200 : 404, {
'Content-Type': 'application/json',
});
response.end(
JSON.stringify(
isPublishRegistry
? {
name,
'dist-tags': {latest: '1.0.0'},
versions: {'1.0.0': {name, version: '1.0.0'}},
}
: {error: 'Not found'},
),
);
});
server.listen(0, '127.0.0.1');
await once(server, 'listening');
t.after(() => promisify(server.close).call(server));
const address = server.address();
assert.ok(address && typeof address !== 'string');
const baseUrl = `http://127.0.0.1:${address.port}`;
const registryIndex = args.indexOf('--registry');
if (registryIndex !== -1) {
assert.equal(args[registryIndex + 1], publishRegistry);
args[registryIndex + 1] = `${baseUrl}/verdaccio/`;
}

await run(process.execPath, [path.join(repoRoot, script), ...args, packages], {
cwd: root,
timeout: 60000,
env: {
...process.env,
NPM_CONFIG_REGISTRY: `${baseUrl}/proxy/`,
NPM_CONFIG_USERCONFIG: userConfig,
NPM_CONFIG_GLOBALCONFIG: globalConfig,
NPM_CONFIG_CACHE: path.join(root, 'cache'),
NPM_CONFIG_FETCH_RETRIES: '0',
NPM_CONFIG_FETCH_TIMEOUT: '2000',
},
});

assert.deepEqual(await fs.readdir(packages), ['1.0.1.tgz']);
assert.ok(requests.includes(`/verdaccio/${name}`));
assert.ok(!requests.some(request => request.startsWith('/proxy/')));
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"postinstall": "yarn build",
"release-notes": "yarn workspace @rnw-scripts/generate-release-notes release-notes",
"spellcheck": "npx cspell",
"test": "node --test .ado/tests/detect-release-build.test.cjs && lage test --verbose --passWithNoTests",
"test": "node --test .ado/tests/detect-release-build.test.cjs .ado/tests/verdaccio-pruning.test.cjs && lage test --verbose --passWithNoTests",
"validate-overrides": "react-native-platform-override validate",
"fork-sync": "node packages/@rnw-scripts/fork-sync/lib-commonjs/sync.js",
"fork-sync:status": "yarn fork-sync --dep fmt --status"
Expand Down