Skip to content

Commit 9271f3a

Browse files
committed
Some updates
1 parent 305e0f0 commit 9271f3a

File tree

3 files changed

+62
-78
lines changed

3 files changed

+62
-78
lines changed

package-lock.json

+25-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "typebundle",
33
"version": "0.7.0",
4-
"description": "A personalized build process for projects.",
4+
"description": "A personalized build process for Node.js projects using Babel-compiled TypeScript.",
55
"main": "dist/index.js",
66
"source": "src/index.js",
77
"bin": {
@@ -46,23 +46,22 @@
4646
"@rollup/plugin-json": "^4.0.1",
4747
"@rollup/plugin-node-resolve": "^7.0.0",
4848
"builtin-modules": "^3.1.0",
49-
"fs-extra": "^9.0.0",
5049
"mri": "^1.1.4",
51-
"rollup": "^1.29.1",
50+
"rollup": "^2.2.0",
5251
"rollup-plugin-babel": "^4.3.3",
53-
"rollup-plugin-dts": "^1.2.1",
52+
"rollup-plugin-dts": "^1.3.0",
5453
"rollup-plugin-terser": "^5.1.2",
5554
"tiny-glob": "^0.2.6",
56-
"typescript": "^3.7.4"
55+
"typescript": "^3.8.3"
5756
},
5857
"devDependencies": {
5958
"@babel/node": "^7.6.3",
60-
"@newswire/prettier-config": "^2.0.0",
59+
"@newswire/prettier-config": "^3.0.0",
6160
"@types/fs-extra": "^8.0.1",
6261
"@types/mri": "^1.1.0",
6362
"@types/node": "^13.5.0",
6463
"np": "^5.1.2",
65-
"prettier": "^1.18.2"
64+
"prettier": "^2.0.2"
6665
},
6766
"prettier": "@newswire/prettier-config"
6867
}

src/index.ts

+31-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// native
2-
import { basename, format, parse, resolve } from 'path';
2+
import { promises as fs } from 'fs';
3+
import { basename, dirname, format, parse, resolve } from 'path';
34

45
// packages
56
import babelPresetEnv from '@babel/preset-env';
67
import babelPresetTypescript from '@babel/preset-typescript';
78
import builtinModules from 'builtin-modules';
8-
import { outputFile, readFile } from 'fs-extra';
9-
import {
10-
rollup,
11-
watch,
12-
OutputOptions,
13-
InputOptions,
14-
RollupWarning,
15-
RollupWatchOptions,
16-
} from 'rollup';
9+
import { rollup, watch } from 'rollup';
1710
import babel from 'rollup-plugin-babel';
1811
import commonjs from '@rollup/plugin-commonjs';
1912
import dts from 'rollup-plugin-dts';
@@ -22,11 +15,30 @@ import nodeResolve from '@rollup/plugin-node-resolve';
2215
import { terser } from 'rollup-plugin-terser';
2316
import glob from 'tiny-glob';
2417

18+
// types
19+
import type {
20+
OutputOptions,
21+
InputOptions,
22+
RollupWarning,
23+
RollupWatchOptions,
24+
} from 'rollup';
25+
2526
const extensions = ['.ts', '.js', '.mjs'];
2627
const hashbangRegex = /^#!(.*)/;
2728

29+
async function outputFile(filepath: string, data: any) {
30+
// determine the directory
31+
const dir = dirname(filepath);
32+
33+
// make sure the directory exists
34+
await fs.mkdir(dir, { recursive: true });
35+
36+
// write the file
37+
await fs.writeFile(filepath, data);
38+
}
39+
2840
async function getConfig(cwd: string) {
29-
const pkg = await readFile(resolve(cwd, 'package.json'), 'utf8');
41+
const pkg = await fs.readFile(resolve(cwd, 'package.json'), 'utf8');
3042

3143
return JSON.parse(pkg);
3244
}
@@ -58,7 +70,7 @@ async function createRollupConfig({
5870

5971
const inputOptions: InputOptions = {
6072
input,
61-
external: id => {
73+
external: (id) => {
6274
// a special case for when we are importing a local index
6375
if (withMultipleInputs && id === '.') {
6476
return true;
@@ -92,8 +104,11 @@ async function createRollupConfig({
92104
exclude: 'node_modules/**',
93105
extensions,
94106
presets: [
95-
[babelPresetEnv, { targets: { node: nodeTarget } }],
96-
babelPresetTypescript,
107+
[babelPresetEnv, { bugfixes: true, targets: { node: nodeTarget } }],
108+
[
109+
babelPresetTypescript,
110+
{ allowDeclareFields: true, onlyRemoveTypeImports: true },
111+
],
97112
],
98113
}),
99114
compress &&
@@ -224,7 +239,7 @@ export async function bundler({
224239
const entry = inputs[idx];
225240

226241
const externalDependencies = pkgDependencies.concat(
227-
inputs.filter(e => e !== entry)
242+
inputs.filter((e) => e !== entry)
228243
);
229244

230245
const options = await createRollupConfig({
@@ -256,7 +271,7 @@ export async function bundler({
256271

257272
const watcher = watch(watchOptions);
258273

259-
watcher.on('event', event => {
274+
watcher.on('event', (event) => {
260275
switch (event.code) {
261276
case 'ERROR':
262277
throw event.error;

0 commit comments

Comments
 (0)