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

Build es6 modules (ESM) with rollup #213

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: Node CI

on:
on:
push:
branches: [ main ]
pull_request:
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
- "16" # active LTS
- "14"
- "14.0.0" # lowest supported
os:
os:
- ubuntu-latest
- macos-latest
- windows-latest
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ dist
# TypeScript source files are intended to be shipped,
# as they provide definition context and typing for downstream users.
# The compiler configs are shipped, so downstream users can inherit from them.
# So the result is a mix of binary- and source-distribution.
!/src/
!/tsconfig.*
!/webpack.*
!/rollup.*

/test/
/tests/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports.stringify = undefined
let possibleStringifier
for (const file of possibleStringifiers) {
try {
possibleStringifier = require(`./stringifiers/${file}`)
possibleStringifier = require(`./stringifiers/${file}.cjs`)
if (typeof possibleStringifier === 'function') {
module.exports.stringify = possibleStringifier
break
Expand Down
9 changes: 9 additions & 0 deletions libs/universal-node-xml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"type": "commonjs",
"main": "./index.cjs",
"types": "./index.d.ts",
"optionalDependencies": {
"xmlbuilder2": "^3.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
*/

const { create } = require('xmlbuilder2')
const { getNS, makeIndent } = require('./helpers')
const { getNS, makeIndent } = require('./helpers.cjs')

module.exports = typeof create === 'function'
? stringify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
const assert = require('assert')
const { suite, test } = require('mocha')

const stringify = require('./xmlbuilder2')
const stringify = require('./xmlbuilder2.cjs')

suite('stringify with xmlbuilder2', () => {
assert.strictEqual(typeof stringify, 'function')
Expand Down
140 changes: 134 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"xmlbuilder2": "^3.0.2"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.5.0",
"@types/mocha": "^9.1.1",
"@types/node": ">=14",
"@types/webpack": "^5.28.0",
Expand All @@ -54,16 +55,18 @@
"eslint-plugin-simple-import-sort": "^8.0.0",
"mocha": "10.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^2.79.0",
"ts-loader": "9.3.1",
"tslib": "^2.4.0",
"typescript": "4.8.2",
"webpack": "5.74.0",
"webpack-cli": "4.10.0",
"xmlbuilder2": "^3.0.2"
},
"browser": "./dist.web/lib.js",
"types": "./src/index.node.ts",
"main": "./dist.node/index.node.js",
"exports": "./dist.node/index.node.js",
"main": "./dist.node/lib.cjs",
"module": "./dist.node/lib.mjs",
"directories": {
"doc": "./docs",
"src": "./src",
Expand All @@ -77,7 +80,7 @@
"lint": "tsc --noEmit",
"build": "run-p --aggregate-output -l build:*",
"prebuild:node": "node -r fs -e 'fs.rmSync(\"dist.node\",{recursive:true,force:true})'",
"build:node": "tsc -b ./tsconfig.node.json",
"build:node": "rollup -c rollup.config.js",
"prebuild:web": "node -r fs -e 'fs.rmSync(\"dist.web\",{recursive:true,force:true})'",
"build:web": "webpack build",
"cs-fix": "eslint --fix .",
Expand Down
54 changes: 54 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const typescript = require('@rollup/plugin-typescript')

/**
* @see {@link https://rollupjs.org}
* @type {import('rollup').RollupOptions}
*/
module.exports = {
input: 'src/index.node.ts',
external: [
// region own shipped
/\.\/(?:libs|res)\//,
// endregion own shipped
// region externals dependencies
'packageurl-js'
// endregion externals dependencies
],
treeshake: false,
output: [
{
file: 'dist.node/lib.cjs',
format: 'cjs',
strict: true,
sourcemap: false,
compact: true
},
{
file: 'dist.node/lib.dev.cjs',
format: 'cjs',
strict: true,
sourcemap: true,
compact: false
},
{
file: 'dist.node/lib.mjs',
format: 'esm',
strict: true,
sourcemap: false,
compact: true
},
{
file: 'dist.node/lib.dev.mjs',
format: 'esm',
strict: true,
sourcemap: true,
compact: false
}
],
plugins: [
typescript({
tsconfig: 'tsconfig.node.json',
sourceMap: true
})
]
}
Loading