Skip to content

Commit

Permalink
mjs (esm) & cjs build;"type": "module"
Browse files Browse the repository at this point in the history
  • Loading branch information
btakita committed Jul 21, 2021
1 parent 3d670d3 commit 61a8869
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function ({ version, experimental }?: {
version?: string | undefined;
experimental?: boolean | undefined;
}): string[];
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
"description": "List of node.js builtin modules",
"repository": "juliangruber/builtins",
"license": "MIT",
"main": "index.js",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.js",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/mjs/index.js"
}
},
"types": "./dist/mjs/index.d.ts",
"files": [],
"scripts": {
"build": "rimraf cjs/**,mjs/** && tsc -p tsconfig.cjs.json && tsc -p tsconfig.mjs.json",
"release": "np",
"test": "node test.js"
},
"dependencies": {
"semver": "^7.0.0"
"semver": "github:MylesBorins/node-semver#alternative-esm"
},
"devDependencies": {
"np": "^6.1.0",
"prettier-standard": "^15.0.0",
"standard": "^14.0.2",
"tape": "^4.11.0"
"np": "^6.5.0",
"prettier-standard": "^15.0.1",
"rimraf": "^3.0.2",
"standard": "^14.3.4",
"tape": "^4.13.3",
"typescript": "^4.3.5"
}
}
10 changes: 5 additions & 5 deletions index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

var semver = require('semver')
import semver from 'semver'

module.exports = function ({
export default function builtins({
version = process.version,
experimental = false
} = {}) {
var coreModules = [
} = {}):string[] {
const coreModules = [
'assert',
'buffer',
'child_process',
Expand Down Expand Up @@ -59,6 +59,6 @@ module.exports = function ({
if (semver.gte(version, '12.16.0') && experimental) {
coreModules.push('wasi')
}

return coreModules
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "dist/cjs",
"declarationDir": "dist/cjs"
}
}
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2019",
"module": "ESNext",
"declaration": true,
"rootDir": "src",
"outDir": "dist/mjs",
"declarationDir": "dist/mjs",
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["mjs"]
}
7 changes: 7 additions & 0 deletions tsconfig.mjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/mjs",
"declarationDir": "dist/mjs"
}
}

0 comments on commit 61a8869

Please sign in to comment.