Skip to content

Commit

Permalink
use .mjs for node esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Feb 28, 2022
1 parent f6bd7e1 commit 69d1edd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions jest.esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

//Jest doc: https://jestjs.io/docs/ecmascript-modules

const bundleName = process.env.BUNDLE_ENV === 'browser' ? 'esm.browser.mjs' : 'esm.node.mjs';
const OktaAuth = `<rootDir>/build/bundles-for-validation/esm/${bundleName}`;
const OktaAuth = process.env.BUNDLE_ENV === 'browser' ?
`<rootDir>/build/bundles-for-validation/esm/esm.browser.mjs` :
`<rootDir>/build/esm/esm.node.mjs`;
const testEnvironment = process.env.BUNDLE_ENV === 'browser' ? 'jsdom' : 'node';

export default {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"homepage": "https://github.com/okta/okta-auth-js",
"license": "Apache-2.0",
"main": "build/cjs/index.js",
"module": "build/esm/esm.node.js",
"module": "build/esm/esm.node.mjs",
"browser": "build/dist/okta-auth-js.umd.js",
"types": "build/lib/index.d.ts",
"exports": {
"node": {
"import": "./build/esm/esm.node.js",
"import": "./build/esm/esm.node.mjs",
"require": "./build/cjs/index.js"
},
"browser": {
Expand Down
13 changes: 2 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,10 @@ export default [
output: [
{
format: 'esm',
file: 'build/esm/esm.node.js',
file: 'build/esm/esm.node.mjs',
exports: 'named',
sourcemap: true
},
// not emit test bundle for development
(process.env.NODE_ENV !== 'development' && {
// generate ems bundle for jest test, ".mjs" extension should be used
// this bundle is excluded from the release package
format: 'esm',
file: 'build/bundles-for-validation/esm/esm.node.mjs',
exports: 'named',
sourcemap: true
})
}
]
}
];
7 changes: 7 additions & 0 deletions test/apps/node-esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */
import { OktaAuth } from "@okta/okta-auth-js";

const oktaAuth = new OktaAuth({
issuer: 'https://xxx.okta.com',
clientId: '0oal89rzfrHjIVqQw5d6'
});
12 changes: 12 additions & 0 deletions test/apps/node-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"name": "@okta/test.app.node-esm",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@okta/okta-auth-js": "*"
}
}

0 comments on commit 69d1edd

Please sign in to comment.