Skip to content

Commit ae55a6c

Browse files
authored
Merge pull request #363 from preactjs/refactor/build-scripts
refactor: Build scripts & output directories
2 parents 3044ac2 + dad2550 commit ae55a6c

File tree

7 files changed

+31
-43
lines changed

7 files changed

+31
-43
lines changed

config/node-13-exports.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const copy = (filename) => {
99
};
1010

1111
copy('index');
12-
copy('jsx');
13-
copy('stream');
14-
copy('stream-node');
12+
copy('jsx/index');
13+
copy('stream/index');
14+
copy('stream/node/index');

config/node-commonjs.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const filePath = (file) => path.join(process.cwd(), 'dist', file);
88

99
// Main entry
1010
fs.copyFileSync(filePath('index.js'), filePath('commonjs.js'));
11-
fs.copyFileSync(filePath('index.js.map'), filePath('commonjs.js.map'));
1211

1312
const source = [
1413
`const mod = require('./commonjs');`,
@@ -21,13 +20,12 @@ const source = [
2120
fs.writeFileSync(filePath('index.js'), source, 'utf-8');
2221

2322
// JSX entry
24-
fs.copyFileSync(filePath('jsx.js'), filePath('jsx-entry.js'));
25-
fs.copyFileSync(filePath('jsx.js.map'), filePath('jsx-entry.js.map'));
23+
fs.copyFileSync(filePath('jsx/index.js'), filePath('jsx/commonjs.js'));
2624

2725
const sourceJsx = [
28-
`const entry = require('./jsx-entry');`,
26+
`const entry = require('./commonjs');`,
2927
`entry.default.render = entry.render;`,
3028
`entry.default.shallowRender = entry.shallowRender;`,
3129
`module.exports = entry.default;`
3230
].join('\n');
33-
fs.writeFileSync(filePath('jsx.js'), sourceJsx, 'utf-8');
31+
fs.writeFileSync(filePath('jsx/index.js'), sourceJsx, 'utf-8');

config/node-verify-exports.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ assert(typeof mainCjs.render === 'function');
2020
})();
2121

2222
// JSX CJS
23-
const jsxCjs = require(filePath('jsx.js'));
23+
const jsxCjs = require(filePath('jsx/index.js'));
2424
assert(typeof jsxCjs === 'function');
2525
assert(typeof jsxCjs.render === 'function');
2626
assert(typeof jsxCjs.shallowRender === 'function');
2727

2828
// JSX ESM
2929
(async () => {
30-
const jsxESM = await import(filePath('jsx.mjs'));
30+
const jsxESM = await import(filePath('jsx/index.mjs'));
3131
assert(typeof jsxESM.default === 'function');
3232
assert(typeof jsxESM.render === 'function');
3333
assert(typeof jsxESM.shallowRender === 'function');

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,44 @@
77
"umd:main": "dist/index.umd.js",
88
"module": "dist/index.module.js",
99
"jsnext:main": "dist/index.module.js",
10-
"types": "src/index.d.ts",
10+
"types": "dist/index.d.ts",
1111
"exports": {
1212
".": {
13-
"types": "./src/index.d.ts",
13+
"types": "./dist/index.d.ts",
1414
"browser": "./dist/index.module.js",
1515
"umd": "./dist/index.umd.js",
1616
"import": "./dist/index.mjs",
1717
"require": "./dist/index.js"
1818
},
1919
"./jsx": {
20-
"types": "./jsx.d.ts",
21-
"browser": "./dist/jsx.module.js",
22-
"umd": "./dist/jsx.umd.js",
23-
"import": "./dist/jsx.mjs",
24-
"require": "./dist/jsx.js"
20+
"types": "./dist/jsx.d.ts",
21+
"browser": "./dist/jsx/index.module.js",
22+
"umd": "./dist/jsx/index.umd.js",
23+
"import": "./dist/jsx/index.mjs",
24+
"require": "./dist/jsx/index.js"
2525
},
2626
"./stream": {
2727
"types": "./dist/stream.d.ts",
28-
"browser": "./dist/stream.module.js",
29-
"import": "./dist/stream.mjs",
30-
"require": "./dist/stream.js"
28+
"browser": "./dist/stream/index.module.js",
29+
"import": "./dist/stream/index.mjs",
30+
"require": "./dist/stream/index.js"
3131
},
3232
"./stream-node": {
3333
"types": "./dist/stream-node.d.ts",
34-
"import": "./dist/stream-node.mjs",
35-
"require": "./dist/stream-node.js"
34+
"import": "./dist/stream/node/index.mjs",
35+
"require": "./dist/stream/node/index.js"
3636
},
3737
"./package.json": "./package.json"
3838
},
3939
"scripts": {
4040
"bench": "BABEL_ENV=test node -r @babel/register benchmarks index.js",
4141
"bench:v8": "BABEL_ENV=test microbundle benchmarks/index.js -f modern --alias benchmarkjs-pretty=benchmarks/lib/benchmark-lite.js --external none --target node --no-compress --no-sourcemap --raw -o benchmarks/.v8.mjs && v8 --module benchmarks/.v8.modern.js",
42-
"build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s transpile:stream && npm run -s copy-typescript-definition",
42+
"build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s transpile:stream && npm run -s transpile:stream-node && npm run -s copy-typescript-definition",
4343
"postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js && node ./config/node-verify-exports.js",
44-
"transpile": "microbundle src/index.js -f es,cjs,umd --target web --external preact",
45-
"transpile:stream": "microbundle src/stream.js -o dist/stream.js -f es,cjs,umd --external preact && microbundle src/stream-node.js -o dist/stream-node.js -f es,cjs,umd --target node --external preact",
46-
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx.js --target web --external preact && microbundle dist/jsx.js -o dist/jsx.js -f cjs --external preact",
44+
"transpile": "microbundle src/index.js -f es,cjs,umd",
45+
"transpile:stream": "microbundle src/stream.js -o dist/stream/index.js -f es,cjs,umd",
46+
"transpile:stream-node": "microbundle src/stream-node.js -o dist/stream/node/index.js -f es,cjs,umd --target node",
47+
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx/index.js -f es,cjs,umd && microbundle dist/jsx/index.js -o dist/jsx/index.js -f cjs",
4748
"copy-typescript-definition": "copyfiles -f src/*.d.ts dist",
4849
"test": "eslint src test && tsc && npm run test:mocha && npm run test:mocha:compat && npm run test:mocha:debug && npm run bench",
4950
"test:mocha": "BABEL_ENV=test mocha -r @babel/register -r test/setup.js test/*.test.jsx",
@@ -143,14 +144,12 @@
143144
"baseline-rts": "npm:preact-render-to-string@latest",
144145
"preact": "^10.13.0",
145146
"prettier": "^2.2.1",
147+
"pretty-format": "^3.8.0",
146148
"sinon": "^9.2.2",
147149
"sinon-chai": "^3.5.0",
148150
"typescript": "^5.0.0",
149151
"web-streams-polyfill": "^3.2.1"
150152
},
151-
"dependencies": {
152-
"pretty-format": "^3.8.0"
153-
},
154153
"prettier": {
155154
"singleQuote": true,
156155
"trailingComma": "none",

test/preact-render-to-string-tests.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"forceConsistentCasingInFileNames": true
2020
},
2121
"files": [
22-
"src/index.d.ts",
23-
"test/preact-render-to-string-tests.tsx"
22+
"src/index.d.ts"
2423
]
25-
}
24+
}

0 commit comments

Comments
 (0)