Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: esm env var issue - OKTA-407958 #844

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
/build/lib
/build/types
/build/cjs
/build/esm
/samples/templates
/samples/generated/webpack-spa/public/*-bundle.*
/samples/generated/express-direct-auth-dynamic
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- [#832](https://github.com/okta/okta-auth-js/pull/832) Fixes issues with refresh tokens
- [#839](https://github.com/okta/okta-auth-js/pull/839) Fixes `@okta/okta-idx-js` missing core-js dependency.
- [#844](https://github.com/okta/okta-auth-js/pull/844) Fixes ES module includes `SDK_VERSION` placeholder issue

### Other

Expand Down
22 changes: 22 additions & 0 deletions babel.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const sdkVersion = require('./package.json').version;
module.exports = {
sourceMaps: true,
'presets': [
'@babel/typescript',
[
'@babel/preset-env', {
'targets': {
'esmodules': true
},
'modules': false
}
]],
'plugins': [
'@babel/plugin-transform-typescript',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-runtime',
['inline-replace-variables', {
'SDK_VERSION': sdkVersion
}]
]
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"type": "commonjs",
"main": "build/cjs/index.js",
"module": "build/lib/index.js",
"module": "build/esm/index.js",
"browser": "build/dist/okta-auth-js.umd.js",
"types": "build/lib/index.d.ts",
"repository": {
Expand Down Expand Up @@ -40,6 +40,7 @@
"build:cdn": "cross-env NODE_ENV=production webpack --config webpack.cdn.config.js -p",
"build:web": "cross-env NODE_ENV=production webpack --config webpack.config.js --output-library-target=umd -p",
"build:cjs": "cross-env babel lib -d build/cjs --config-file ./babel.cjs.js --extensions \".ts\",\".js\" --source-maps",
"build:esm": "cross-env babel lib -d build/esm --config-file ./babel.esm.js --extensions \".ts\",\".js\" --source-maps",
"build:polyfill": "cross-env NODE_ENV=production webpack --config webpack.polyfill.config.js --output-library-target=umd -p",
"generate:samples": "yarn --cwd samples build && yarn install --ignore-scripts",
"dev:samples": "yarn --cwd samples dev",
Expand Down
19 changes: 13 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ const BUNDLE_LIB_CMD = 'yarn build:web';
const BUNDLE_CDN_CMD = 'yarn build:cdn';
const BUNDLE_POLYFILL_CMD = 'yarn build:polyfill';
const DIST_DIR = `${BUILD_DIR}/dist`; // will be uploaded to CDN
const BABEL_CMD = 'yarn build:cjs';
const TS_CMD = 'yarn tsc';
const BABEL_ESM = 'yarn build:esm';
const BABEL_CJS = 'yarn build:cjs';
const TS_CMD = 'yarn tsc --emitDeclarationOnly';

shell.echo('Start building...');

shell.rm('-Rf', `${BUILD_DIR}/*`);
shell.mkdir('-p', `${DIST_DIR}`);

// Run typescript to generate ESM module source
// Generate types
if (shell.exec(TS_CMD).code !== 0) {
shell.echo(chalk.red('Error: Typescript compilation failed'));
shell.exit(1);
Expand All @@ -43,9 +44,15 @@ if (shell.exec(BUNDLE_POLYFILL_CMD).code !== 0) {
}
shell.echo(chalk.green('Webpack completed'));

// Babelify node/server code
if (shell.exec(BABEL_CMD).code !== 0) {
shell.echo(chalk.red('Error: Babel failed'));
// Babelify ES module
if (shell.exec(BABEL_ESM).code !== 0) {
shell.echo(chalk.red('Error: Babel esm failed'));
shell.exit(1);
}

// Babelify node/server commonJS code
if (shell.exec(BABEL_CJS).code !== 0) {
shell.echo(chalk.red('Error: Babel cjs failed'));
shell.exit(1);
}

Expand Down
13 changes: 0 additions & 13 deletions test/types/index.d.ts

This file was deleted.

Loading