Skip to content

Commit

Permalink
Switch npm package to ESM
Browse files Browse the repository at this point in the history
Change the npm package type to `module`, so that `.js` files are treated as ESM
by default. All of the JS scripts that run in Node had already been converted to
ESM, except for the Karma config, which has to remain CommonJS.
  • Loading branch information
robertknight committed Apr 16, 2024
1 parent 0bbf3a0 commit 7ba6eff
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
},
"overrides": [
{
"files": ["*.mjs"],
"files": ["*.js"],
"excludedFiles": ["h/**"],
"env": { "node": true },
"parserOptions": { "sourceType": "module" }
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY .yarn ./.yarn
RUN yarn install --immutable

# Build h js/css.
COPY .babelrc gulpfile.mjs rollup.config.mjs ./
COPY .babelrc gulpfile.js rollup.config.js ./
COPY h/static ./h/static
RUN yarn build

Expand Down
8 changes: 4 additions & 4 deletions gulpfile.mjs → gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import svgmin from 'gulp-svgmin';

const IS_PRODUCTION_BUILD = process.env.NODE_ENV === 'production';

gulp.task('build-js', () => buildJS('./rollup.config.mjs'));
gulp.task('watch-js', () => watchJS('./rollup.config.mjs'));
gulp.task('build-js', () => buildJS('./rollup.config.js'));
gulp.task('watch-js', () => watchJS('./rollup.config.js'));

gulp.task('build-css', () =>
buildCSS([
Expand Down Expand Up @@ -107,8 +107,8 @@ gulp.task(
gulp.task('test', () =>
runTests({
bootstrapFile: './h/static/scripts/tests/bootstrap.js',
karmaConfig: './h/static/scripts/karma.config.js',
rollupConfig: './rollup-tests.config.mjs',
karmaConfig: './h/static/scripts/karma.config.cjs',
rollupConfig: './rollup-tests.config.js',
testsPattern: 'h/static/scripts/**/*-test.js',
}),
);
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "h",
"private": true,
"version": "0.0.0",
"type": "module",
"description": "The Internet, peer reviewed.",
"scripts": {
"build": "gulp build",
"checkformatting": "prettier --check *.mjs h/static/scripts",
"format": "prettier --list-different --write *.mjs h/static/scripts",
"checkformatting": "prettier --check *.js h/static/scripts",
"format": "prettier --list-different --write *.js h/static/scripts",
"lint": "eslint h/static/scripts",
"test": "gulp test"
},
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7ba6eff

Please sign in to comment.