diff --git a/tools/e2e-tests/scripts/create-app.js b/tools/e2e-tests/scripts/create-app.js index 14315eb75c..fc11504356 100644 --- a/tools/e2e-tests/scripts/create-app.js +++ b/tools/e2e-tests/scripts/create-app.js @@ -18,6 +18,7 @@ const path = require('path'); const fs = require('fs-extra'); const execa = require('execa'); +const { linkLocalRspack } = require('./link-rspack'); const REPO_ROOT = path.resolve(__dirname, '../../..'); const METEOR_EXECUTABLE = path.join(REPO_ROOT, 'meteor'); @@ -363,12 +364,8 @@ async function setupFromApp(appName, destDir, { isMonorepo = false, force = fals ...execEnv, }); - log.step('Updating Meteor npm dependencies...'); - await execa(METEOR_EXECUTABLE, ['update', '--npm'], { - cwd: meteorAppDir, - stdio: 'inherit', - ...execEnv, - }); + log.step('Linking local @meteorjs/rspack...'); + await linkLocalRspack(meteorAppDir, { env: envVars }); if (isMonorepo) { log.step('Running meteor npm install at root level...'); @@ -430,12 +427,8 @@ async function setupFromSkeleton(skeletonName, destDir, { force = false } = {}) ...execEnv, }); - log.step('Updating Meteor npm dependencies...'); - await execa(METEOR_EXECUTABLE, ['update', '--npm'], { - cwd: destDir, - stdio: 'inherit', - ...execEnv, - }); + log.step('Linking local @meteorjs/rspack...'); + await linkLocalRspack(destDir, { env: envVars }); log.step('Running meteor npm install...'); await execa(METEOR_EXECUTABLE, ['npm', 'install'], { cwd: destDir, stdio: 'inherit', ...execEnv }); diff --git a/tools/e2e-tests/scripts/link-rspack.js b/tools/e2e-tests/scripts/link-rspack.js new file mode 100644 index 0000000000..5e8b6bbb97 --- /dev/null +++ b/tools/e2e-tests/scripts/link-rspack.js @@ -0,0 +1,77 @@ +#!/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 } = {}) { + 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 '); + process.exit(1); + } + linkLocalRspack(path.resolve(appDir)).catch(err => { + console.error(err.message); + process.exit(1); + }); +} diff --git a/tools/e2e-tests/test-helpers.js b/tools/e2e-tests/test-helpers.js index 2261d0d8ab..f1728472d5 100644 --- a/tools/e2e-tests/test-helpers.js +++ b/tools/e2e-tests/test-helpers.js @@ -38,41 +38,11 @@ const npmLinkLocalRspack = process.env.NPM_LINK_RSPACK !== 'false'; const WAIT_ON = isCI ? 2000 : 500; +const { linkLocalRspack: _linkLocalRspack } = require('./scripts/link-rspack'); + async function linkLocalRspack(appDir) { if (!npmLinkLocalRspack) return; - const repoRoot = path.resolve(process.cwd(), '..', '..'); - - const meteorBin = path.join(repoRoot, "meteor"); - console.log(`Running meteor update --npm in ${appDir}...`); - (await execa(meteorBin, ["update", "--npm"], { - cwd: appDir, - stdio: "inherit", - })); - - const rspackPackageDir = path.join(repoRoot, 'npm-packages', 'meteor-rspack'); - const constantsPath = path.join(repoRoot, 'packages', 'rspack', 'lib', 'constants.js'); - const constantsContent = await fs.readFile(constantsPath, '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: rspackPackageDir } - ); - } - console.log(`Installing ignore-loader in the app...`); - await execa('npm', ['install', 'ignore-loader', '--save'], { cwd: appDir }); - console.log(`Linking local meteor-rspack from ${rspackPackageDir}...`); - await execa('npm', ['link', rspackPackageDir], { cwd: appDir }); - console.log('Local meteor-rspack linked successfully.'); + await _linkLocalRspack(appDir); } /**