Skip to content

Commit

Permalink
Enable esm named exports (#2382)
Browse files Browse the repository at this point in the history
* Enable esm named exports

* Lint cjs files
  • Loading branch information
perrin4869 authored Nov 3, 2021
1 parent b0cf544 commit eba42cc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions build.js → build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ try {
// We seem to have it already
}

/**
* @param entryPoint
* @param config
* @param done
*/
function makeBundle(entryPoint, config, done) {
browserify(entryPoint, config).bundle(function (err, buffer) {
if (err) {
Expand All @@ -39,7 +44,8 @@ makeBundle(
},
function (bundle) {
var script = preamble + bundle;
fs.writeFileSync("pkg/sinon.js", script);
fs.writeFileSync("pkg/sinon.cjs", script);
fs.writeFileSync("pkg/sinon.js", script); // WebWorker can only load js files
}
);

Expand All @@ -53,7 +59,7 @@ makeBundle(
},
function (bundle) {
var script = preamble + bundle;
fs.writeFileSync("pkg/sinon-no-sourcemaps.js", script);
fs.writeFileSync("pkg/sinon-no-sourcemaps.cjs", script);
}
);

Expand Down
3 changes: 3 additions & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"test-runnable-examples": "docs/release-source/release/examples/run-test.sh",
"test": "npm run test-node && npm run test-headless && npm run test-webworker && npm run test-esm",
"check-dependencies": "dependency-check package.json --no-dev --ignore-module esm",
"build": "node ./build.js",
"build": "node ./build.cjs",
"build-docs": "cd docs; bundle exec jekyll build",
"serve-docs": "cd docs; bundle exec jekyll serve --incremental --verbose",
"lint": "eslint '**/*.{js,mjs}'",
"lint": "eslint '**/*.{js,cjs,mjs}'",
"pretest-webworker": "npm run build",
"prebuild": "rimraf pkg && npm run check-dependencies",
"postbuild": "npm run test-esm-bundle",
Expand Down Expand Up @@ -117,6 +117,11 @@
"browser": "./lib/sinon.js",
"main": "./lib/sinon.js",
"module": "./pkg/sinon-esm.js",
"exports": {
"require": "./pkg/sinon.cjs",
"import": "./pkg/sinon-esm.js"
},
"type": "module",
"cdn": "./pkg/sinon.js",
"jsdelivr": "./pkg/sinon.js",
"esm": {
Expand Down
3 changes: 3 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

0 comments on commit eba42cc

Please sign in to comment.