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 import es modules for node #91

Closed
wants to merge 3 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
10 changes: 8 additions & 2 deletions packages/data-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "@virgilsecurity/data-utils",
"version": "1.0.0",
"version": "1.0.1",
"description": "Library that contains different functions / classes that are used for data manipulation in different Virgil Security libraries.",
"main": "./dist/node.cjs.js",
"module": "./dist/node.es.js",
"browser": {
"./dist/node.cjs.js": "./dist/browser.cjs.js",
"./dist/node.es.js": "./dist/browser.es.js"
},
"exports": {
".": {
"import": "./dist/node.es.mjs",
"require": "./dist/node.cjs.js"
}
},
"typings": "./dist/types/node.d.ts",
"files": [
"dist"
Expand All @@ -22,7 +28,7 @@
"prepare": "npm run clean && npm run build"
},
"dependencies": {
"@virgilsecurity/crypto-types": "1.0.0",
"@virgilsecurity/crypto-types": "1.1.1",
"buffer": "^5.4.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-utils/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const createNodeEntry = format => ({
input: path.join(sourcePath, 'node.ts'),
output: {
format,
file: path.join(outputPath, `node.${format}.js`),
file: path.join(outputPath, `node.${format}.${format === FORMAT.ES ? 'mjs' : 'js'}`),
},
plugins: [
typescript({
Expand Down
8 changes: 7 additions & 1 deletion packages/init-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "@virgilsecurity/init-utils",
"version": "1.0.0",
"version": "1.0.1",
"description": "Initialization utility for Virgil Security Inc. libraries",
"main": "./dist/init-utils.cjs.js",
"module": "./dist/init-utils.es.js",
"exports": {
".": {
"import": "./dist/init-utils.es.mjs",
"require": "./dist/init-utils.cjs.js"
}
},
"typings": "./dist/types/index.d.ts",
"files": [
"dist"
Expand Down
11 changes: 7 additions & 4 deletions packages/init-utils/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ const path = require('path');

const typescript = require('rollup-plugin-typescript2');

const formats = ['cjs', 'es'];
const { FORMAT, getOutputFilename } = require('../../utils/build');

const sourcePath = path.join(__dirname, 'src');
const outputPath = path.join(__dirname, 'dist');

const createEntry = format => ({
const createEntry = (format, isNodeES) => ({
external: ['eventemitter3'],
input: path.join(sourcePath, 'index.ts'),
output: {
format,
file: path.join(outputPath, `init-utils.${format}.js`),
file: path.join(
outputPath,
getOutputFilename('init-utils', undefined, format, isNodeES ? 'mjs' : 'js'),
),
},
plugins: [
typescript({
Expand All @@ -27,4 +30,4 @@ const createEntry = format => ({
],
});

module.exports = formats.map(createEntry);
module.exports = [createEntry(FORMAT.CJS), createEntry(FORMAT.ES), createEntry(FORMAT.ES, true)];
12 changes: 9 additions & 3 deletions packages/pythia-crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "@virgilsecurity/pythia-crypto",
"version": "1.1.3",
"version": "1.1.4",
"description": "Virgil Pythia Crypto library.",
"main": "./dist/node.cjs.js",
"module": "./dist/node.es.js",
"exports": {
".": {
"import": "./dist/node.es.mjs",
"require": "./dist/node.cjs.js"
}
},
"browser": {
"./dist/node.cjs.js": "./browser.cjs.js",
"./dist/node.es.js": "./browser.es.js"
Expand Down Expand Up @@ -31,8 +37,8 @@
"dependencies": {
"@virgilsecurity/core-pythia": "^1.0.1",
"@virgilsecurity/crypto-types": "1.1.1",
"@virgilsecurity/data-utils": "^1.0.0",
"@virgilsecurity/init-utils": "^1.0.0"
"@virgilsecurity/data-utils": "^1.0.1",
"@virgilsecurity/init-utils": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.2.7",
Expand Down
10 changes: 7 additions & 3 deletions packages/pythia-crypto/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ const createBrowserEntry = (target, cryptoType, format, declaration = false) =>
};
};

const createNodeJsEntry = (cryptoType, format) => {
const createNodeJsEntry = (cryptoType, format, isNodeES) => {
const pythiaEntryPoint = path.join(
'@virgilsecurity',
'core-pythia',
getCryptoEntryPointName(TARGET.NODE, cryptoType, format),
getCryptoEntryPointName(TARGET.NODE, cryptoType, format, isNodeES),
);
const extension = isNodeES ? 'mjs' : 'js';

return {
input: path.join(sourceDir, 'index.ts'),
output: {
format,
file: path.join(outputDir, getOutputFilename(TARGET.NODE, cryptoType, format)),
file: path.join(outputDir, getOutputFilename(TARGET.NODE, cryptoType, format, extension)),
},
external: builtinModules
.concat(Object.keys(packageJson.dependencies))
Expand Down Expand Up @@ -127,8 +129,10 @@ module.exports = [
createBrowserEntry(TARGET.BROWSER, CRYPTO_TYPE.WASM, FORMAT.UMD),
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.CJS),
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.ES),
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.ES, true),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.CJS),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.ES),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.ES, true),
createBrowserEntry(TARGET.WORKER, CRYPTO_TYPE.ASMJS, FORMAT.CJS),
createBrowserEntry(TARGET.WORKER, CRYPTO_TYPE.ASMJS, FORMAT.ES),
createBrowserEntry(TARGET.WORKER, CRYPTO_TYPE.ASMJS, FORMAT.UMD),
Expand Down
8 changes: 7 additions & 1 deletion packages/sdk-crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "@virgilsecurity/sdk-crypto",
"version": "1.1.1",
"version": "1.1.2",
"description": "Virgil JavaScript Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.",
"main": "./dist/sdk-crypto.cjs.js",
"module": "./dist/sdk-crypto.es.js",
"exports": {
".": {
"import": "./dist/sdk-crypto.es.mjs",
"require": "./dist/sdk-crypto.cjs.js"
}
},
"typings": "./dist/types/index.d.ts",
"files": [
"dist"
Expand Down
11 changes: 7 additions & 4 deletions packages/sdk-crypto/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ const path = require('path');

const typescript = require('rollup-plugin-typescript2');

const formats = ['cjs', 'es'];
const { FORMAT, getOutputFilename } = require('../../utils/build');

const sourcePath = path.join(__dirname, 'src');
const outputPath = path.join(__dirname, 'dist');

const createEntry = format => ({
const createEntry = (format, isNodeES) => ({
input: path.join(sourcePath, 'index.ts'),
output: {
format,
file: path.join(outputPath, `sdk-crypto.${format}.js`),
file: path.join(
outputPath,
getOutputFilename('sdk-crypto', undefined, format, isNodeES ? 'mjs' : 'js'),
),
},
plugins: [
typescript({
Expand All @@ -26,4 +29,4 @@ const createEntry = format => ({
],
});

module.exports = formats.map(createEntry);
module.exports = [createEntry(FORMAT.CJS), createEntry(FORMAT.ES), createEntry(FORMAT.ES, true)];
14 changes: 10 additions & 4 deletions packages/virgil-crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "virgil-crypto",
"version": "4.2.2",
"version": "4.2.3",
"description": "Virgil JavaScript Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.",
"main": "./dist/node.cjs.js",
"module": "./dist/node.es.js",
Expand All @@ -9,6 +9,12 @@
"./dist/node.es.js": "./browser.es.js"
},
"typings": "./dist/types/index.d.ts",
"exports": {
".": {
"import": "./dist/node.es.mjs",
"require": "./dist/node.cjs.js"
}
},
"files": [
"dist",
"browser.cjs.js",
Expand Down Expand Up @@ -41,9 +47,9 @@
"dependencies": {
"@virgilsecurity/core-foundation": "^1.2.1",
"@virgilsecurity/crypto-types": "1.1.1",
"@virgilsecurity/data-utils": "^1.0.0",
"@virgilsecurity/init-utils": "^1.0.0",
"@virgilsecurity/sdk-crypto": "^1.0.0"
"@virgilsecurity/data-utils": "^1.0.1",
"@virgilsecurity/init-utils": "^1.0.1",
"@virgilsecurity/sdk-crypto": "^1.1.2"
},
"devDependencies": {
"@types/chai": "^4.2.7",
Expand Down
10 changes: 7 additions & 3 deletions packages/virgil-crypto/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ const createBrowserEntry = (target, cryptoType, format, declaration = false) =>
};
};

const createNodeJsEntry = (cryptoType, format) => {
const createNodeJsEntry = (cryptoType, format, isNodeES) => {
const foundationEntryPoint = path.join(
'@virgilsecurity',
'core-foundation',
getCryptoEntryPointName(TARGET.NODE, cryptoType, format),
getCryptoEntryPointName(TARGET.NODE, cryptoType, format, isNodeES),
);
const extension = isNodeES ? 'mjs' : 'js';

return {
input: path.join(sourceDir, 'index.ts'),
output: {
format,
file: path.join(outputDir, getOutputFilename(TARGET.NODE, cryptoType, format)),
file: path.join(outputDir, getOutputFilename(TARGET.NODE, cryptoType, format, extension)),
},
external: builtinModules
.concat(Object.keys(packageJson.dependencies))
Expand Down Expand Up @@ -119,8 +121,10 @@ const createNodeJsEntry = (cryptoType, format) => {
module.exports = [
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.CJS),
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.ES),
createNodeJsEntry(CRYPTO_TYPE.ASMJS, FORMAT.ES, true),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.CJS),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.ES),
createNodeJsEntry(CRYPTO_TYPE.WASM, FORMAT.ES, true),
createBrowserEntry(TARGET.BROWSER, CRYPTO_TYPE.WASM, FORMAT.CJS, true),
createBrowserEntry(TARGET.BROWSER, CRYPTO_TYPE.WASM, FORMAT.ES),
createBrowserEntry(TARGET.BROWSER, CRYPTO_TYPE.WASM, FORMAT.UMD),
Expand Down
5 changes: 3 additions & 2 deletions utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ const TARGET = {
const getOutputFilename = (target, cryptoType, format, extension = 'js') =>
`${target}${cryptoType === CRYPTO_TYPE.ASMJS ? '.asmjs' : ''}.${format}.${extension}`;

const getCryptoEntryPointName = (target, cryptoType, format) => {
const getCryptoEntryPointName = (target, cryptoType, format, isNodeES) => {
const myCryptoType = cryptoType === CRYPTO_TYPE.ASMJS ? '.asmjs' : '';
const myFormat = format === FORMAT.UMD ? 'es' : format;
return `${target}${myCryptoType}.${myFormat}.js`;
const extension = isNodeES ? 'mjs' : 'js';
return `${target}${myCryptoType}.${myFormat}.${extension}`;
};

module.exports = {
Expand Down