Skip to content

Commit

Permalink
New: Rollup-based JavaScript builder and bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Feb 20, 2024
1 parent 72ebc89 commit 25dcef4
Show file tree
Hide file tree
Showing 151 changed files with 2,201 additions and 1,399 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"devDependencies": {
"@techor/jest": "workspace:^",
"@techor/jest-dom": "workspace:^",
"@types/fs-extra": "^9.0.13",
"@types/node": "^20.11.0",
"commitlint-config-techor": "workspace:^",
Expand All @@ -36,14 +37,20 @@
"jest-puppeteer": "^6.1.1",
"parent-module": "^3.0.0",
"puppeteer": "^21.0.1",
"rollup": "^4.11.0",
"semantic-release-config-techor": "workspace:^",
"strip-ansi": "^7.0.1",
"sucrase": "^3.32.0",
"tmp": "^0.2.1",
"ts-dedent": "^2.2.0",
"tsx": "^3.12.6"
"tsx": "^4.7.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-swc": "^0.3.0",
"@rollup/plugin-typescript": "^11.1.6",
"@rollup/pluginutils": "^5.1.0",
"cross-env": "^7.0.3",
"turbo": "^1.11.2"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/conventional-changelog-config/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "conventional-changelog-techor",
"scripts": {
"build": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --loader:.hbs=file --asset-names=[dir]/[name] --platform=node --external:esbuild --external:fast-glob --external:require-from-string --external:@techor/extend --external:@techor/fs --external:upath",
"dev": "pnpm build --watch",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
"test": "pnpm build && jest",
"type-check": "tsc --noEmit",
"lint": "eslint src"
Expand Down Expand Up @@ -34,6 +36,7 @@
"preset"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
Expand Down
8 changes: 8 additions & 0 deletions packages/conventional-changelog-config/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions,
input: 'src/index.ts',
output: { file: 'dist/index.js', format: 'cjs' },
}
9 changes: 6 additions & 3 deletions packages/conventional-changelog-config/src/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
parserOpts: require('./parser-opts'),
writerOpts: require('./writer-opts')
import parserOpts from './parser-opts'
import writerOpts from './writer-opts'

export default {
parserOpts,
writerOpts
}
15 changes: 10 additions & 5 deletions packages/conventional-changelog-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = async () => ({
conventionalChangelog: require('./changelog'),
parserOpts: require('./parser-opts'),
recommendedBumpOpts: require('./recommended-bump'),
writerOpts: require('./writer-opts')
import conventionalChangelog from './changelog'
import parserOpts from './parser-opts'
import recommendedBumpOpts from './recommended-bump'
import writerOpts from './writer-opts'

export default async () => ({
conventionalChangelog,
parserOpts,
recommendedBumpOpts,
writerOpts
})
2 changes: 1 addition & 1 deletion packages/conventional-changelog-config/src/parser-opts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
headerPattern: /^([A-Z]\w*)(?:\(([0-9A-Z`_#~].*)\))?: ([0-9A-Z`_#~].*)$/,
headerCorrespondence: [
'type',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const parserOpts = require('./parser-opts')
const { commits: aronCommits } = require('techor-conventional-commits')
import parserOpts from './parser-opts'
import { commits as techorCommits } from 'techor-conventional-commits'

module.exports = {
export default {
parserOpts,
whatBump: (commits) => {
let level = null
let majorCount = 0
let MinorCount = 0
let patchCount = 0
commits.forEach(({ type }) => {
const conventionalCommit = aronCommits.find(({ type: eachType }) => eachType === type)
const conventionalCommit = techorCommits.find(({ type: eachType }) => eachType === type)
if (conventionalCommit) {
switch (conventionalCommit.release) {
case 'major':
Expand Down
14 changes: 4 additions & 10 deletions packages/conventional-changelog-config/src/writer-opts.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import compareFunc from 'compare-func'
import { commits } from 'techor-conventional-commits'
import mainTemplatePath from './templates/template.hbs'
import footerPartialPath from './templates/footer.hbs'
import commitPartialPath from './templates/commit.hbs'
import { readFileSync } from 'fs'
import path from 'path'
import mainTemplate from './templates/template.hbs'
import footerPartial from './templates/footer.hbs'
import commitPartial from './templates/commit.hbs'
import https from 'node:https'

const mainTemplate = readFileSync(path.resolve(__dirname, mainTemplatePath), 'utf-8')
const footerPartial = readFileSync(path.resolve(__dirname, footerPartialPath), 'utf-8')
const commitPartial = readFileSync(path.resolve(__dirname, commitPartialPath), 'utf-8')

module.exports = {
export default {
transform: async (commit, context) => {
const issues = []
if (commit.header) {
Expand Down
5 changes: 2 additions & 3 deletions packages/conventional-changelog-config/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs, { writeFile, writeFileSync } from 'fs'
import fs, { writeFileSync } from 'fs'
import path, { resolve } from 'path'
import exec from '../../../utils/exec'
import commit from '../../../utils/commit'
import initFakeGit from '../../../utils/init-fake-git'
import dotenv from 'dotenv'

const createPreset = require('../dist')
import createPreset from '../dist'
const conventionalChangelogCore = require('conventional-changelog-core')

dotenv.config({ path: path.resolve(__dirname, '../../../.env') })
Expand Down
1 change: 0 additions & 1 deletion packages/conventional-commits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"preset"
],
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
11 changes: 5 additions & 6 deletions packages/cross-import/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "cross-import",
"type": "module",
"scripts": {
"build:cjs": "esbuild src/index.ts --outfile=dist/index.js --format=cjs --minify --sourcemap --platform=node",
"build:esm": "esbuild src/index.ts --outfile=dist/index.mjs --format=esm --minify --sourcemap --platform=node",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
"test": "node -r sucrase/register ./tests/real && jest",
"test": "pnpm build:main && node ./tests/real.mjs && jest",
"type-check": "tsc --noEmit",
"lint": "eslint src"
},
Expand Down Expand Up @@ -43,14 +43,13 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"main": "./dist/index.cjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/cross-import/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions
}
2 changes: 1 addition & 1 deletion packages/cross-import/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jiti from 'jiti/dist/jiti'
import jiti from 'jiti'
import { transform } from 'sucrase'

export default function crossImport(modulePath: string): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import crossImport from '../src'
import crossImport from '../dist/index.mjs'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

/**
* 測試 require cache 在真實 Node 環境運作時是否有被正確的清除
Expand Down
3 changes: 2 additions & 1 deletion packages/explore-config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('jest').Config} */
export default {
preset: '@techor/jest'
preset: '@techor/jest',
transformIgnorePatterns: ['node_modules/(?!callsites)/']
}
11 changes: 5 additions & 6 deletions packages/explore-config/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "explore-config",
"type": "module",
"scripts": {
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --sourcemap --platform=node --external:@techor/extend --external:@techor/log --external:@techor/log --external:@techor/glob --external:cross-import",
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --minify --sourcemap --platform=node --external:@techor/extend --external:@techor/log --external:@techor/log --external:@techor/glob --external:cross-import",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
"test": "jest",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"type-check": "tsc --noEmit",
"lint": "eslint src"
},
Expand Down Expand Up @@ -37,14 +37,13 @@
"explore"
],
"sideEffects": false,
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"main": "./dist/index.cjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/explore-config/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions
}
5 changes: 5 additions & 0 deletions packages/explore-config/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import exploreConfig from '../src'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

it('read .js config', () => {
const config = exploreConfig('master.css.js', { cwd: __dirname })
Expand Down
9 changes: 4 additions & 5 deletions packages/extend/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@techor/extend",
"type": "module",
"scripts": {
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --sourcemap --platform=node",
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --minify --sourcemap --platform=node",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
Expand Down Expand Up @@ -36,14 +36,13 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"main": "./dist/index.cjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/extend/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions
}
4 changes: 1 addition & 3 deletions packages/extend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,4 @@ export default function extend(...sources: any[]) {
})

return target
}

export { extend }
}
9 changes: 4 additions & 5 deletions packages/fs/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@techor/fs",
"type": "module",
"scripts": {
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --sourcemap --platform=node",
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --minify --sourcemap --platform=node",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
Expand Down Expand Up @@ -42,14 +42,13 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"main": "./dist/index.cjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/fs/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions
}
9 changes: 4 additions & 5 deletions packages/glob/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@techor/glob",
"type": "module",
"scripts": {
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --sourcemap --platform=node --external:fast-glob --external:upath",
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --minify --sourcemap --platform=node --external:fast-glob --external:upath",
"build:main": "rollup --config rollup.config.mjs",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
Expand Down Expand Up @@ -39,14 +39,13 @@
"publishConfig": {
"access": "public"
},
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"main": "./dist/index.cjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/glob/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import commonOptions from '../../rollup.config.mjs'

/** @type {import('rollup').RollupOptions} */
export default {
...commonOptions
}
Loading

0 comments on commit 25dcef4

Please sign in to comment.