Skip to content

Commit

Permalink
Merge pull request #89 from embroider-build/NullVoxPopuli-patch-1
Browse files Browse the repository at this point in the history
Allow direct importing of the standalone module
  • Loading branch information
ef4 authored Dec 17, 2024
2 parents 5bed7d6 + 75f6283 commit 8278f31
Show file tree
Hide file tree
Showing 9 changed files with 4,305 additions and 665 deletions.
4,883 changes: 4,224 additions & 659 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
"types": "./index.d.cts",
"default": "./pkg/node.cjs"
}
},
"./standalone": {
"import": {
"types": "./index.d.ts",
"default": "./pkg/standalone.js"
},
"require": {
"types": "./pkg/stubs/require-types.d.cts",
"default": "./pkg/stubs/require.cjs"
}
}
},
"files": [
Expand All @@ -30,24 +40,28 @@
"scripts": {
"build": "./build.sh",
"prepack": "./build.sh",
"ci:node": "mocha 'test/*.{js,cjs}'",
"ci:node": "mocha 'test/node/*.{js,cjs}'",
"ci:browser": "vitest --browser.name=chrome --browser.headless",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:package": "publint",
"lint:published-types": "attw --pack",
"lint:published-types": "attw --profile node16 --pack",
"start": "vite",
"test": "npm run ci:node"
"test": "npm run ci:node && npm run ci:browser"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.2",
"@arethetypeswrong/cli": "^0.17.1",
"@vitest/browser": "^2.1.8",
"chai": "^4.3.7",
"code-equality-assertions": "1.0.1",
"concurrently": "^8.2.2",
"eslint": "^8.44.0",
"mocha": "^10.2.0",
"publint": "^0.2.6",
"publint": "^0.2.12",
"release-plan": "^0.5.0",
"toml": "^3.0.0",
"vite": "^5.0.4"
"vite": "^5.0.4",
"vitest": "^2.1.8",
"webdriverio": "^9.4.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
16 changes: 16 additions & 0 deletions pkg/stubs/require-types.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This type is deliberately wrong.
*
* To require use:
* - require('content-tag')
*
* To import:
* - import 'content-tag';
* - import 'content-tag/standalone';
* - import('content-tag');
* - import('content-tag/standalone');
*/
class Preprocessor {}

module.exports = { Preprocessor };

14 changes: 14 additions & 0 deletions pkg/stubs/require.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Not all our entrypoints support all environments.
*
* This stub file is to appears are-the-types-wrong, but also give developers in require / CJS environments
* more useful information when they try to require an ESM
*/
class Preprocessor {
constructor() {
throw new Error(`Tried to create a Preprocessor using require() when an import was expected. Please change to using import.`);
}
}


module.exports = { Preprocessor };
11 changes: 11 additions & 0 deletions test/browser/alias-exports.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, it, expect } from 'vitest';


describe('package.json#export aliases', () => {
it(`'.' === './standalone' when importing`, async () => {
let main = await import('content-tag');
let standalone = await import('content-tag/standalone');

expect(main.Preprocessor).to.equal(standalone.Preprocessor);
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vite';
/**
* Browser-only vitest config.
* We're currently using Mocha for node testing.
*/
export default defineConfig({
test: {
include: ['test/browser/**/*'],
browser: {
name: 'chrome',
headless: true,
provider: 'webdriverio',
providerOptions: {
launch: {
devtools: false,
}
}
}
}
})

0 comments on commit 8278f31

Please sign in to comment.