/
githubmirror
/
meteor
Обзор
Документация
Войти
/
githubmirror
/
meteor
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
devel
tools/e2e-tests/scripts/link-rspack.js
89 строк
3 KB
Vlad Lasky
test(e2e): fail fast when the test app directory is missing (#14577)
15 июл 2026, 23:37
Не верифицирован
15 июл 2026, 23:37
15dabd5
Код
Авторство
О чём код?
#!/usr/bin/env node /** * Links the local npm-packages/meteor-rspack into a Meteor app so it runs * against the latest dev version. * * Steps: * 1. Run `meteor update --npm` in the app * 2. Install the matching @rspack/core and @rspack/cli versions into the * local meteor-rspack package (read from packages/rspack/lib/constants.js) * 3. Install `ignore-loader` in the app * 4. `npm link` the local meteor-rspack into the app * */ const path = require('path'); const fs = require('fs'); const execa = require('execa'); const REPO_ROOT = path.resolve(__dirname, '..', '..', '..'); const METEOR_EXECUTABLE = path.join(REPO_ROOT, 'meteor'); const RSPACK_PACKAGE_DIR = path.join(REPO_ROOT, 'npm-packages', 'meteor-rspack'); const CONSTANTS_PATH = path.join(REPO_ROOT, 'packages', 'rspack', 'lib', 'constants.js'); async function linkLocalRspack(appDir, { env } = {}) { if (!appDir || !fs.existsSync(appDir)) { // Fail fast with the real story: when an earlier app-creation phase // fails or times out, the suite's shared tempDir stays undefined and // this used to surface as a confusing "missing projectDir!" from a // `meteor update --npm` spawned with cwd undefined (i.e. the jest // working directory), burying the initiating error. throw new Error( `linkLocalRspack: invalid app directory (${appDir}). ` + 'The test app was probably never created - look at the earlier ' + 'app-creation step in this suite for the initiating failure.' ); } const execOpts = env ? { env: { ...process.env, ...env } } : {}; console.log(`Running meteor update --npm in ${appDir}...`); await execa(METEOR_EXECUTABLE, ['update', '--npm'], { cwd: appDir, stdio: 'inherit', ...execOpts, }); const constantsContent = fs.readFileSync(CONSTANTS_PATH, 'utf8'); const rspackVersionMatch = constantsContent.match( /DEFAULT_RSPACK_VERSION\s*=\s*['"]([^'"]+)['"]/ ); const rspackVersion = rspackVersionMatch?.[1]; if (rspackVersion) { console.log(`Installing @rspack/core@${rspackVersion} and @rspack/cli@${rspackVersion}...`); await execa( 'npm', [ 'install', `@rspack/core@${rspackVersion}`, `@rspack/cli@${rspackVersion}`, '--no-save', '--no-package-lock', ], { cwd: RSPACK_PACKAGE_DIR } ); } console.log('Installing ignore-loader in the app...'); await execa('npm', ['install', 'ignore-loader', '--save'], { cwd: appDir }); console.log(`Linking local meteor-rspack from ${RSPACK_PACKAGE_DIR}...`); await execa('npm', ['link', RSPACK_PACKAGE_DIR], { cwd: appDir }); console.log('Local meteor-rspack linked successfully.'); } module.exports = { linkLocalRspack, REPO_ROOT, METEOR_EXECUTABLE, RSPACK_PACKAGE_DIR }; // CLI mode if (require.main === module) { const appDir = process.argv[2]; if (!appDir) { console.error('Usage: node link-rspack.js <appDir>'); process.exit(1); } linkLocalRspack(path.resolve(appDir)).catch(err => { console.error(err.message); process.exit(1); }); }