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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
},
overrides: [
{
files: ['test/**/*.js'],
files: ['test/**/*-test.js', 'test/**/*_test.js'],
plugins: ['mocha'],
env: {
mocha: true,
Expand Down
32 changes: 25 additions & 7 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,48 @@ on:
- cron: '0 6 * * 0'

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install yarn
run: npm install -g yarn

- name: install dependencies
run: yarn install --frozen-lockfile

- name: lint
run: yarn lint

test:
name: Test
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node_version: ['8', '10', '12']
node_version: ['20', '22', '24']

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
version: ${{ matrix.node_version }}
node-version: ${{ matrix.node_version }}

- name: install yarn
run: npm install -g yarn cross-env

- name: install dependencies
run: yarn install --frozen-lockfile

- name: lint
run: yarn lint

- name: test
run: cross-env CI=true yarn test
46 changes: 17 additions & 29 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ import ConsoleUI from '../types/console-ui';
import WatchDetector from 'watch-detector';
import UI from 'console-ui';

enum EnvironmentType {
PRODUCTION = 'production',
DEVELOPMENT = 'development',
}

enum WatcherType {
POLLING = 'polling',
WATCHMAN = 'watchman',
NODE = 'node',
}

interface ServeOptions {
host: string;
port: string;
Expand All @@ -30,8 +19,8 @@ interface ServeOptions {
outputPath?: string;
cwd?: string;
noWatch?: boolean;
watcher?: WatcherType,
environment: EnvironmentType;
watcher?: string;
environment: string;
prod?: boolean;
dev?: boolean;

Expand All @@ -43,8 +32,8 @@ interface BuildOptions {
outputPath?: string;
cwd?: string;
watch?: boolean;
watcher?: WatcherType;
environment: EnvironmentType;
watcher?: string;
environment: string;
prod?: boolean;
dev?: boolean;
}
Expand All @@ -55,10 +44,9 @@ function buildBrocfileOptions(options: { environment: string }) {
};
}

async function getBuilder(options: { environment: string }) {
function getBuilder(options: { environment: string }) {
const brocfile = broccoli.loadBrocfile(options);
const instance = await Promise.resolve(brocfile(buildBrocfileOptions(options)));
return new broccoli.Builder(instance);
return new broccoli.Builder(brocfile(buildBrocfileOptions(options)));
}

function getWatcher(options: { watch?: boolean }) {
Expand All @@ -85,9 +73,9 @@ function buildWatcherOptions(options: { watcher?: string }, ui: ConsoleUI) {

return {
saneOptions: {
poll: watcher === WatcherType.POLLING,
watchman: watcher === WatcherType.WATCHMAN,
node: watcher === WatcherType.NODE || !watcher,
poll: watcher === 'polling',
watchman: watcher === 'watchman',
node: watcher === 'node' || !watcher,
},
};
}
Expand Down Expand Up @@ -147,14 +135,14 @@ export = function broccoliCLI(args: string[], ui = new UI()) {
.option('-e, --environment <environment>', 'build environment [development]', 'development')
.option('--prod', 'alias for --environment=production')
.option('--dev', 'alias for --environment=development')
.action(async (options: ServeOptions) => {
.action((options: ServeOptions) => {
if (options.prod) {
options.environment = EnvironmentType.PRODUCTION;
options.environment = 'production';
} else if (options.dev) {
options.environment = EnvironmentType.DEVELOPMENT;
options.environment = 'development';
}

const builder = await getBuilder(options);
const builder = getBuilder(options);
const Watcher = getWatcher(options);
const outputDir = options.outputPath;
const watcher = new Watcher(
Expand Down Expand Up @@ -205,7 +193,7 @@ export = function broccoliCLI(args: string[], ui = new UI()) {
.option('-e, --environment <environment>', 'build environment [development]', 'development')
.option('--prod', 'alias for --environment=production')
.option('--dev', 'alias for --environment=development')
.action(async (outputDir: string, options: BuildOptions) => {
.action((outputDir: string, options: BuildOptions) => {
if (outputDir && options.outputPath) {
ui.writeLine('option --output-path and [target] cannot be passed at same time', 'ERROR');
return process.exit(1);
Expand All @@ -220,9 +208,9 @@ export = function broccoliCLI(args: string[], ui = new UI()) {
}

if (options.prod) {
options.environment = EnvironmentType.PRODUCTION;
options.environment = 'production';
} else if (options.dev) {
options.environment = EnvironmentType.DEVELOPMENT;
options.environment = 'development';
}

try {
Expand All @@ -236,7 +224,7 @@ export = function broccoliCLI(args: string[], ui = new UI()) {
throw e;
}

const builder = await getBuilder(options);
const builder = getBuilder(options);
const Watcher = getWatcher(options);
const outputTree = new TreeSync(builder.outputPath, outputDir);
const watcher = new Watcher(
Expand Down
17 changes: 13 additions & 4 deletions lib/load_brocfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import path from 'path';
import findup from 'findup-sync';
import esm from 'esm';

const esmRequire = esm(module);

interface LoadBrocfileOptions {
brocfilePath?: string;
cwd?: string;
Expand Down Expand Up @@ -37,8 +35,19 @@ function requireBrocfile(brocfilePath: string) {
// Load brocfile via ts-node
brocfile = require(brocfilePath);
} else {
// Load brocfile via esm shim
brocfile = esmRequire(brocfilePath);
try {
brocfile = require(brocfilePath);
} catch (err) {
// Node error when requiring an ESM file from CJS on Node <= 20
if (err && err.code === 'ERR_REQUIRE_ESM') {
// esm is side-effectful so only load when needed
const esmRequire = esm(module);

// Load brocfile via esm shim
brocfile = esmRequire(brocfilePath);
}
throw err;
}
}

// ESM `export default X` is represented as module.exports = { default: X }
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint": "eslint --ext .ts,.js lib/ test/",
"lint:fix": "eslint --ext .ts,.js lib/ test/ --fix",
"prepare": "yarn build",
"pretest": "multidep test/multidep.json",
"pretest": "node test/utils/multidep.js test/multidep.json",
"test": "yarn build && mocha -r test/utils/requires",
"test:debug": "yarn build && mocha --inspect-brk -r test/utils/requires",
"watch": "tsc --watch"
Expand All @@ -35,23 +35,23 @@
"@types/chai": "^4.2.9",
"@types/chai-as-promised": "^7.1.2",
"@types/express": "^4.17.2",
"ansi-html": "^0.0.7",
"ansi-html": "^0.0.9",
"broccoli-node-info": "^2.1.0",
"broccoli-slow-trees": "^3.0.1",
"broccoli-source": "^3.0.0",
"commander": "^4.1.1",
"connect": "^3.6.6",
"console-ui": "^3.0.4",
"esm": "^3.2.4",
"findup-sync": "^4.0.0",
"handlebars": "^4.7.3",
"esm": "^3.2.25",
"findup-sync": "^5.0.0",
"handlebars": "^4.7.8",
"heimdalljs": "^0.2.6",
"heimdalljs-logger": "^0.1.9",
"https": "^1.0.0",
"mime-types": "^2.1.26",
"resolve-path": "^1.4.0",
"rimraf": "^3.0.2",
"sane": "^4.0.0",
"sane": "^5.0.1",
"tmp": "^0.0.33",
"tree-sync": "^2.0.0",
"underscore.string": "^3.2.2",
Expand All @@ -78,13 +78,14 @@
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"execa": "^5.1.1",
"fixturify": "^1.1.0",
"got": "^9.0.0",
"longjohn": "^0.2.12",
"mocha": "^7.1.0",
"multidep": "^2.0.2",
"portfinder": "^1.0.25",
"prettier": "^1.19.1",
"rsvp": "^3.1.0",
"semver": "^6.3.0",
"sinon": "^9.0.0",
"sinon-chai": "^3.5.0",
Expand All @@ -94,7 +95,7 @@
"typescript": "~3.8.3"
},
"engines": {
"node": "8.* || >= 10.*"
"node": ">= 20.*"
},
"files": [
"dist"
Expand Down
5 changes: 0 additions & 5 deletions test/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Sinon from 'sinon';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
import MultidepRequire from 'multidep';
import MultidepRequire from './utils/multidep/index';
import semver from 'semver';
import heimdall from 'heimdalljs';

Expand Down
16 changes: 0 additions & 16 deletions test/cli_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,6 @@ describe('cli', function() {
});
});

context('with promise in a Brocfile default export', function() {
it('closes process on completion', async function() {
await cli([
'node',
'broccoli',
'build',
'dist',
'--brocfile-path',
'../../async-brocfile/Brocfile.js',
]);
chai.expect(process.exitCode).to.eql(0);
chai.expect(exitStub).to.be.calledWith(0);
chai.expect(fs.existsSync('dist')).to.be.true;
});
});

context('with param --brocfile-path', function() {
it('closes process on completion', async function() {
await cli(['node', 'broccoli', 'build', 'dist', '--brocfile-path', '../Brocfile.js']);
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/async-brocfile/Brocfile.js

This file was deleted.

17 changes: 14 additions & 3 deletions test/load_brocfile_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import BroccoliSource from 'broccoli-source';
import chai from 'chai';
import esm from 'esm';

const esmRequire = esm(module);

const projectPath = 'test/fixtures/project';
const projectPathEsm = 'test/fixtures/project-esm';
const projectPathTs = 'test/fixtures/project-ts';
Expand All @@ -13,7 +11,20 @@ const projectPathTsConfig = 'test/fixtures/project-ts-tsconfig';
const brocfileFixture = require('../' + projectPath + '/Brocfile.js');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const brocfileFunctionFixture = require('../' + projectPath + '/Brocfile-Function.js');
const brocfileEsmFixture = esmRequire('../' + projectPathEsm + '/Brocfile.js');
const brocfileEsmFixturePath = '../' + projectPathEsm + '/Brocfile.js';
let brocfileEsmFixture;
try {
brocfileEsmFixture = require(brocfileEsmFixturePath);
} catch (err) {
// Node error when requiring an ESM file from CJS on Node <= 20
if (err && err.code === 'ERR_REQUIRE_ESM') {
// esm is side-effectful so only load when needed
const esmRequire = esm(module);
// Load brocfile via esm shim
brocfileEsmFixture = esmRequire(brocfileEsmFixturePath);
}
throw err;
}

describe('loadBrocfile', function() {
let oldCwd = null;
Expand Down
2 changes: 1 addition & 1 deletion test/server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Sinon from 'sinon';
import got from 'got';
import fs from 'fs';
import Watcher from '../lib/watcher';
import multidep from 'multidep';
import multidep from './utils/multidep/index';

const expect = chai.expect;
const multidepRequire = multidep('test/multidep.json');
Expand Down
13 changes: 13 additions & 0 deletions test/utils/multidep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
process.title = 'multidep';

if (process.argv.length !== 3) {
console.error('Usage: multidep path/to/spec.json');
process.exit(1);
}

require('./multidep/index')
.install(process.argv[2])
.catch(function(err) {
console.error(err.stack || err);
process.exit(1);
});
Loading
Loading