Skip to content

Commit

Permalink
core & runtime migrate to rollup typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Nov 26, 2023
1 parent 7eef4fe commit d689476
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 103 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
},
"license": "MIT",
"devDependencies": {
"@microsoft/api-extractor": "^7.38.3",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@tybys/cross-zip": "^3.1.0",
"@tybys/ts-transform-pure-class": "^0.1.1",
"@tybys/tsapi": "^0.6.0",
Expand All @@ -41,6 +46,7 @@
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"fs-extra": "^10.1.0",
"rollup": "^4.5.2",
"ts-clone-node": "^3.0.0",
"typescript": "~5.0.4"
},
Expand Down
6 changes: 0 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
"dependencies": {
"tslib": "^2.4.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.25.1"
},
"scripts": {
"build": "node ./script/build.js"
},
Expand Down
61 changes: 33 additions & 28 deletions packages/core/script/build.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
const path = require('path')
const fs = require('fs-extra')
const rollup = require('rollup')
const ts = require('typescript')
const rollupTypescript = require('@rollup/plugin-typescript').default
const rollupNodeResolve = require('@rollup/plugin-node-resolve').default
const rollupReplace = require('@rollup/plugin-replace').default
const rollupTerser = require('@rollup/plugin-terser').default
const dist = path.join(__dirname, '../dist')
const { compile } = require('@tybys/tsapi')

function build () {
compile(path.join(__dirname, '../tsconfig.json'), {
optionsToExtend: {
target: require('typescript').ScriptTarget.ES5,
outDir: path.join(__dirname, '../lib/es5')
}
})
compile(path.join(__dirname, '../tsconfig.json'), {
optionsToExtend: {
target: require('typescript').ScriptTarget.ES2019,
outDir: path.join(__dirname, '../lib/es2019'),
removeComments: true,
downlevelIteration: false
}
})

/**
* @param {'es5' | 'es2019'} esversion
* @param {ts.ScriptTarget} esversion
* @param {boolean=} minify
* @returns {rollup.RollupOptions}
*/
function createInput (esversion, minify, options) {
function createInput (esversion, minify, external) {
return {
input: path.join(__dirname, '../lib', esversion, 'index.js'),
input: path.join(__dirname, '../src/index.js'),
external,
plugins: [
rollupTypescript({
tsconfig: path.join(__dirname, '../tsconfig.json'),
tslib: path.join(
path.dirname(require.resolve('tslib')),
JSON.parse(fs.readFileSync(path.join(path.dirname(require.resolve('tslib')), 'package.json'))).module
),
compilerOptions: {
target: esversion,
...(esversion !== ts.ScriptTarget.ES5 ? { removeComments: true, downlevelIteration: false } : {})
},
include: [
'./src/**/*'
],
transformers: {
after: [
require('@tybys/ts-transform-pure-class').default
]
}
}),
rollupNodeResolve({
mainFields: ['module', 'main'],
...((options && options.resolveOnly) ? { resolveOnly: options.resolveOnly } : {})
mainFields: ['module', 'main']
}),
rollupReplace({
preventAssignment: true,
Expand All @@ -59,7 +64,7 @@ function build () {

return Promise.all(([
{
input: createInput('es5', false),
input: createInput(ts.ScriptTarget.ES5, false),
output: {
file: path.join(dist, 'emnapi-core.js'),
format: 'umd',
Expand All @@ -69,7 +74,7 @@ function build () {
}
},
{
input: createInput('es5', true),
input: createInput(ts.ScriptTarget.ES5, true),
output: {
file: path.join(dist, 'emnapi-core.min.js'),
format: 'umd',
Expand All @@ -79,7 +84,7 @@ function build () {
}
},
{
input: createInput('es2019', false, { resolveOnly: [/^(?!(tslib)).*?$/] }),
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
output: {
file: path.join(dist, 'emnapi-core.cjs.js'),
format: 'cjs',
Expand All @@ -89,7 +94,7 @@ function build () {
}
},
{
input: createInput('es2019', true, { resolveOnly: [/^(?!(tslib)).*?$/] }),
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
output: {
file: path.join(dist, 'emnapi-core.cjs.min.js'),
format: 'cjs',
Expand All @@ -99,7 +104,7 @@ function build () {
}
},
{
input: createInput('es2019', false, { resolveOnly: [/^(?!(tslib)).*?$/] }),
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
output: {
file: path.join(dist, 'emnapi-core.mjs'),
format: 'esm',
Expand All @@ -109,7 +114,7 @@ function build () {
}
},
{
input: createInput('es2019', true, { resolveOnly: [/^(?!(tslib)).*?$/] }),
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
output: {
file: path.join(dist, 'emnapi-core.min.mjs'),
format: 'esm',
Expand All @@ -119,7 +124,7 @@ function build () {
}
},
{
input: createInput('es5', false, { resolveOnly: [/^(?!(tslib)).*?$/] }),
input: createInput(ts.ScriptTarget.ES5, false, ['tslib']),
output: {
file: path.join(dist, 'emnapi-core.esm-bundler.js'),
format: 'esm',
Expand Down
13 changes: 3 additions & 10 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"allowJs": true,
"target": "ES5",
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmitHelpers": true,
"importHelpers": true,
"importsNotUsedAsValues": "error",
"outDir": "lib",
"paths": {
"tslib" : ["../../node_modules/tslib/tslib.d.ts"]
},
Expand All @@ -17,17 +18,9 @@
"ES2021.WeakRef",
"ES2017.SharedMemory",
"DOM"
],
"plugins": [
{
"transform": "@tybys/ts-transform-pure-class",
"type": "raw",
"after": true
}
]
},
"include": [
"./src/**/*.ts",
"./src/**/*.js"
"./src/**/*"
]
}
7 changes: 0 additions & 7 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
"dependencies": {
"tslib": "^2.4.0"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.25.1"
},
"scripts": {
"build": "node ./script/build.js"
},
Expand Down
Loading

0 comments on commit d689476

Please sign in to comment.