Skip to content

Commit 952aede

Browse files
authored
Merge branch 'master' into patch-1
2 parents 125d05b + 4ef32f1 commit 952aede

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Here's what's coming up for Microbundle:
117117
- [brazilian-utils](https://github.com/brazilian-utils/brazilian-utils) Utils library for specific Brazilian businesses.
118118
- [react-hooks-lib](https://github.com/beizhedenglong/react-hooks-lib) A set of reusable react hooks.
119119
- [mdx-deck-live-code](https://github.com/JReinhold/mdx-deck-live-code) A library for [mdx-deck](https://github.com/jxnblk/mdx-deck) to do live React and JS coding directly in slides.
120+
- [react-router-ext](https://github.com/ri7nz/react-router-ext) An Extended [react-router-dom](https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom) with simple usage.
120121

121122
## 🥂 License
122123

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ function createConfig(options, entry, format, writeMeta) {
418418
}
419419
return externalTest(id);
420420
},
421+
treeshake: {
422+
propertyReadSideEffects: false,
423+
},
421424
plugins: []
422425
.concat(
423426
postcss({
@@ -592,9 +595,6 @@ function createConfig(options, entry, format, writeMeta) {
592595
freeze: false,
593596
esModule: false,
594597
sourcemap: options.sourcemap,
595-
treeshake: {
596-
propertyReadSideEffects: false,
597-
},
598598
format,
599599
name: options.name,
600600
file: resolve(

test/index.test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,34 @@ const rimraf = promisify(_rimraf);
1414
const FIXTURES_DIR = `${__dirname}/fixtures`;
1515
const DEFAULT_SCRIPT = 'microbundle';
1616

17-
const times = (n, fn) => Array.from({ length: n }).map(i => fn(i));
1817
const join = (arr, delimiter = '') => arr.join(delimiter);
19-
const constant = konst => () => konst;
2018

2119
const printTree = (nodes, indentLevel = 0) => {
22-
const indent = join(times(indentLevel, constant(' ')));
20+
const indent = ' '.repeat(indentLevel);
2321
return join(
2422
nodes
2523
.filter(node => node.name[0] !== '.')
26-
.map(
27-
node =>
28-
`${indent}${node.name}\n${
29-
node.type === 'directory'
30-
? printTree(node.children, indentLevel + 1)
31-
: ''
32-
}`,
33-
),
24+
.map(node => {
25+
const isDir = node.type === 'directory';
26+
return `${indent}${node.name}\n${
27+
isDir ? printTree(node.children, indentLevel + 1) : ''
28+
}`;
29+
}),
3430
);
3531
};
3632

33+
const getBuildScript = async (fixturePath, defaultScript) => {
34+
let pkg = {};
35+
try {
36+
pkg = JSON.parse(
37+
await readFile(resolve(fixturePath, 'package.json'), 'utf8'),
38+
);
39+
} catch (err) {
40+
if (err.code !== 'ENOENT') throw err;
41+
}
42+
return (pkg && pkg.scripts && pkg.scripts.build) || defaultScript;
43+
};
44+
3745
const parseScript = (() => {
3846
let parsed;
3947
const prog = createProg(_parsed => (parsed = _parsed));
@@ -65,13 +73,7 @@ describe('fixtures', () => {
6573
await rimraf(resolve(`${fixturePath}/.rts2_cache_es`));
6674
await rimraf(resolve(`${fixturePath}/.rts2_cache_umd`));
6775

68-
let script;
69-
try {
70-
({ scripts: { build: script } = {} } = JSON.parse(
71-
await readFile(resolve(fixturePath, 'package.json'), 'utf8'),
72-
));
73-
} catch (err) {}
74-
script = script || DEFAULT_SCRIPT;
76+
const script = await getBuildScript(fixturePath, DEFAULT_SCRIPT);
7577

7678
const prevDir = process.cwd();
7779
process.chdir(resolve(fixturePath));

0 commit comments

Comments
 (0)