Skip to content

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmurphy committed Mar 27, 2020
1 parent 305e0f0 commit 9271f3a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 78 deletions.
80 changes: 25 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typebundle",
"version": "0.7.0",
"description": "A personalized build process for projects.",
"description": "A personalized build process for Node.js projects using Babel-compiled TypeScript.",
"main": "dist/index.js",
"source": "src/index.js",
"bin": {
Expand Down Expand Up @@ -46,23 +46,22 @@
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
"builtin-modules": "^3.1.0",
"fs-extra": "^9.0.0",
"mri": "^1.1.4",
"rollup": "^1.29.1",
"rollup": "^2.2.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-dts": "^1.2.1",
"rollup-plugin-dts": "^1.3.0",
"rollup-plugin-terser": "^5.1.2",
"tiny-glob": "^0.2.6",
"typescript": "^3.7.4"
"typescript": "^3.8.3"
},
"devDependencies": {
"@babel/node": "^7.6.3",
"@newswire/prettier-config": "^2.0.0",
"@newswire/prettier-config": "^3.0.0",
"@types/fs-extra": "^8.0.1",
"@types/mri": "^1.1.0",
"@types/node": "^13.5.0",
"np": "^5.1.2",
"prettier": "^1.18.2"
"prettier": "^2.0.2"
},
"prettier": "@newswire/prettier-config"
}
47 changes: 31 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
// native
import { basename, format, parse, resolve } from 'path';
import { promises as fs } from 'fs';
import { basename, dirname, format, parse, resolve } from 'path';

// packages
import babelPresetEnv from '@babel/preset-env';
import babelPresetTypescript from '@babel/preset-typescript';
import builtinModules from 'builtin-modules';
import { outputFile, readFile } from 'fs-extra';
import {
rollup,
watch,
OutputOptions,
InputOptions,
RollupWarning,
RollupWatchOptions,
} from 'rollup';
import { rollup, watch } from 'rollup';
import babel from 'rollup-plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
Expand All @@ -22,11 +15,30 @@ import nodeResolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import glob from 'tiny-glob';

// types
import type {
OutputOptions,
InputOptions,
RollupWarning,
RollupWatchOptions,
} from 'rollup';

const extensions = ['.ts', '.js', '.mjs'];
const hashbangRegex = /^#!(.*)/;

async function outputFile(filepath: string, data: any) {
// determine the directory
const dir = dirname(filepath);

// make sure the directory exists
await fs.mkdir(dir, { recursive: true });

// write the file
await fs.writeFile(filepath, data);
}

async function getConfig(cwd: string) {
const pkg = await readFile(resolve(cwd, 'package.json'), 'utf8');
const pkg = await fs.readFile(resolve(cwd, 'package.json'), 'utf8');

return JSON.parse(pkg);
}
Expand Down Expand Up @@ -58,7 +70,7 @@ async function createRollupConfig({

const inputOptions: InputOptions = {
input,
external: id => {
external: (id) => {
// a special case for when we are importing a local index
if (withMultipleInputs && id === '.') {
return true;
Expand Down Expand Up @@ -92,8 +104,11 @@ async function createRollupConfig({
exclude: 'node_modules/**',
extensions,
presets: [
[babelPresetEnv, { targets: { node: nodeTarget } }],
babelPresetTypescript,
[babelPresetEnv, { bugfixes: true, targets: { node: nodeTarget } }],
[
babelPresetTypescript,
{ allowDeclareFields: true, onlyRemoveTypeImports: true },
],
],
}),
compress &&
Expand Down Expand Up @@ -224,7 +239,7 @@ export async function bundler({
const entry = inputs[idx];

const externalDependencies = pkgDependencies.concat(
inputs.filter(e => e !== entry)
inputs.filter((e) => e !== entry)
);

const options = await createRollupConfig({
Expand Down Expand Up @@ -256,7 +271,7 @@ export async function bundler({

const watcher = watch(watchOptions);

watcher.on('event', event => {
watcher.on('event', (event) => {
switch (event.code) {
case 'ERROR':
throw event.error;
Expand Down

0 comments on commit 9271f3a

Please sign in to comment.