diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2f57aae0..63d7d919e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,5 +114,4 @@ jobs: yarn install --ignore-engines --frozen-lockfile - name: Run Mocha Tests run: | - node scripts/fix-node-modules.mjs yarn workspace ember-cli-fastboot test:mocha diff --git a/package.json b/package.json index ae900d830..d01babec3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "test-packages/*" ], "scripts": { - "pretest": "node scripts/fix-node-modules.mjs", "test": "npm-run-all test:*", "test:ember-cli-fastboot": "yarn workspace ember-cli-fastboot test:ember", "test:fastboot": "yarn workspace fastboot test", @@ -20,9 +19,6 @@ "test:extra": "yarn workspace basic-app test:mocha && yarn workspace custom-fastboot-app test:mocha" }, "devDependencies": { - "chalk": "^4.1.2", - "execa": "^5.1.1", - "fs-extra": "^10.0.0", "npm-run-all": "^4.1.5", "release-it": "^14.2.2", "release-it-lerna-changelog": "^3.1.0", diff --git a/packages/ember-cli-fastboot/fix-node-modules.mjs b/packages/ember-cli-fastboot/fix-node-modules.mjs new file mode 100644 index 000000000..9375bec7e --- /dev/null +++ b/packages/ember-cli-fastboot/fix-node-modules.mjs @@ -0,0 +1,47 @@ +/** + * Fix nested packages not using workspace version + * ember-cli-addon-tests will link ember-cli-fastboot and run npm install in the test apps, + * the installation will install fastboot from npm registry rather than workspace version + * + */ + +import path from 'path'; +import fs from 'fs-extra'; +import { fileURLToPath } from 'url'; +import chalk from 'chalk'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const packagesDir = path.resolve(__dirname, '../../packages'); +const nodeModulesDir = path.resolve(__dirname, 'node_modules'); + +// eslint-disable-next-line no-undef +const shouldRestore = process.argv[2]; +if (shouldRestore === '--help' || shouldRestore === '-h') { + console.log(`Usage: node fix-node-modules.mjs [arguments] +Options: + -h, --help print this message + -r, --restore restore node_modules by removing symlinks`); +} else if (shouldRestore === '-r' || shouldRestore === '--restore') { + run(true); +} else { + run(false); +} + +function run(shouldRestore) { + ['fastboot', 'fastboot-express-middleware'].forEach((packageName) => { + const nodeModulesPackageDir = path.join(nodeModulesDir, packageName); + const workspacesPackageDir = path.resolve(packagesDir, packageName); + if (fs.existsSync(nodeModulesPackageDir)) { + console.log(chalk.blue(`remove ${nodeModulesPackageDir}`)); + fs.removeSync(nodeModulesPackageDir); + } + if (!shouldRestore) { + console.log( + chalk.green( + `symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}` + ) + ); + fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir'); + } + }); +} diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index 4ee754a39..b59db3a9b 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -23,7 +23,7 @@ "lint:js:fix": "eslint . --fix", "start": "ember serve", "test": "npm-run-all lint test:*", - "test:mocha": "mocha", + "test:mocha": "node fix-node-modules.mjs && mocha && node fix-node-modules.mjs -r", "test:ember": "ember test", "test:precook": "node node_modules/ember-cli-addon-tests/scripts/precook-node-modules.js" }, @@ -34,7 +34,7 @@ "broccoli-merge-trees": "^3.0.1", "broccoli-plugin": "^1.3.1", "broccoli-persistent-filter": "^3.1.2", - "chalk": "^2.4.1", + "chalk": "^4.1.2", "ember-cli-babel": "^7.26.3", "ember-cli-htmlbars": "^5.7.1", "ember-cli-lodash-subset": "2.0.1", @@ -43,7 +43,7 @@ "fastboot": "3.2.0-beta.2", "fastboot-express-middleware": "3.2.0-beta.2", "fastboot-transform": "^0.1.3", - "fs-extra": "^7.0.0", + "fs-extra": "^10.0.0", "jsdom": "^16.2.2", "json-stable-stringify": "^1.0.1", "md5-hex": "^2.0.0", diff --git a/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html b/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html new file mode 100644 index 000000000..8392fc505 --- /dev/null +++ b/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html @@ -0,0 +1,26 @@ + + + + + + Customized Output Paths + + + + {{content-for "head"}} + + + + + {{content-for "head-footer"}} + + + {{content-for "body"}} + + + + + {{content-for "body-footer"}} + + + diff --git a/scripts/fix-node-modules.mjs b/scripts/fix-node-modules.mjs deleted file mode 100644 index 8109df171..000000000 --- a/scripts/fix-node-modules.mjs +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Fix nested packages not using workspace version - * - * For example, these will download from npm registry rather than using local workspaces, - * the changes won't be reflected during tests if not symlink to worksapces. - * node_modules/ember-cli-fastboot-testing/node_modules/fastboot - * packages/ember-cli-fastboot/node_modules/fastboot-express-middleware - * packages/ember-cli-fastboot/node_modules/fastboot - */ - -import path from 'path'; -import fs from 'fs-extra'; -import { fileURLToPath } from 'url'; -import execa from 'execa'; -import chalk from 'chalk'; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const projectRoot = path.resolve(__dirname, '..'); -const packagesDir = path.resolve(projectRoot, 'packages'); -const packages = fs.readdirSync(packagesDir); -const extraDirs = [ - path.resolve(projectRoot, 'node_modules/ember-cli-fastboot-testing'), - path.resolve(projectRoot, 'node_modules/ember-fetch'), -]; - -[...packages, ...extraDirs].forEach(packageName => { - const packageNodeModules = path.resolve(packagesDir, packageName, 'node_modules'); - console.log(chalk.grey(`Inspecting ${packageNodeModules} ...`)); - packages.forEach(packageNameToLink => { - const nodeModulesPackageDir = path.join(packageNodeModules, packageNameToLink); - const workspacesPackageDir = path.resolve(packagesDir, packageNameToLink); - if (fs.existsSync(nodeModulesPackageDir)) { - console.log(chalk.green(`symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}`)); - fs.removeSync(nodeModulesPackageDir); - fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir'); - } - }); -}); - diff --git a/yarn.lock b/yarn.lock index f90ef3617..9d75e7655 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9650,7 +9650,7 @@ execa@^4.0.2, execa@^4.0.3: signal-exit "^3.0.2" strip-final-newline "^2.0.0" -execa@^5.0.0, execa@^5.1.1: +execa@^5.0.0: version "5.1.1" resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==