Skip to content

Commit

Permalink
cd(node): ban package.json main entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Nov 19, 2023
1 parent 44a75a3 commit 682acc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"node": ">=16.20.0"
},
"module": "./dist/index.mjs",
"main": "./dist/index.node.cjs",
"main": null,
"types": "./dist/index.d.ts",
"typesVersions": {
">=4.2": {
Expand Down
7 changes: 6 additions & 1 deletion test/unit/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ QUnit.module('env', (hooks) => {
delete global.document;
})

QUnit.test('import/require of `main` field of package.json throws', assert => {
assert.rejects(import('../..'), 'should not resolve main');
assert.throws(() => require('../..'), 'should not resolve main');
});

QUnit.test('import/require sets env', async assert => {
const done = assert.async();
global.window = { devicePixelRatio: 1.25 };
global.document = { foo: 'bar' };
const imported = await import('../../dist/index.node.cjs');
const required = require('../..');
const required = require('../../dist/index.node.cjs');
assert.equal(imported.getEnv().document.foo, undefined, 'should be node env');
assert.equal(required.getEnv().document.foo, undefined, 'should be node env');
done();
Expand Down

0 comments on commit 682acc1

Please sign in to comment.