Skip to content

Commit

Permalink
Add support for class properties, fix usage of TypeScript declare
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmurphy committed Mar 28, 2020
1 parent 9271f3a commit 8f38863
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 60 deletions.
87 changes: 36 additions & 51 deletions package-lock.json

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

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
],
"scripts": {
"build": "npm run -s build:babel && npm run -s build:self",
"build:babel": "babel-node --extensions \".ts\" src/cli.ts \"src/{cli,index}.ts\" --target=10 --output=dist --compress --types=types",
"build:self": "node dist/cli.js \"src/{cli,index}.ts\" --target=10 --output=dist --compress --types=types",
"build:babel": "babel-node --extensions \".ts\" src/cli.ts \"src/{cli,index}.ts\" --target=10 --output=dist --compress --types=types --external=@babel",
"build:self": "node dist/cli.js \"src/{cli,index}.ts\" --target=10 --output=dist --compress --types=types --external=@babel",
"prerelease": "npm run build",
"release": "np --no-yarn",
"test": "echo \"Error: no test specified\" && exit 0",
Expand All @@ -39,9 +39,10 @@
},
"homepage": "https://github.com/rdmurphy/typebundle#readme",
"dependencies": {
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.8.3",
"@babel/preset-typescript": "^7.6.0",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
Expand Down
12 changes: 11 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ const mriConfig = {
output: 'dist',
watch: false,
},
string: ['external'],
};

async function main(argv_: string[]) {
const args = mri(argv_.slice(2), mriConfig);

const input = args._[0];
const outputDir = args.output;

const compress = args.compress;

let external;

if (args.external) {
external = Array.isArray(args.external) ? args.external : [args.external];
}

const nodeTarget = args.target;
const outputDir = args.output;
const typesDir = args.types;
const watchBuild = args.watch;

await bundler({
compress,
external,
input,
nodeTarget,
outputDir,
Expand Down
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { basename, dirname, format, parse, resolve } from 'path';

// packages
import babelPresetEnv from '@babel/preset-env';
import babelPresetTypescript from '@babel/preset-typescript';
import babelPluginTransformTypeScript from '@babel/plugin-transform-typescript';
import babelPluginClassProperties from '@babel/plugin-proposal-class-properties';
import builtinModules from 'builtin-modules';
import { rollup, watch } from 'rollup';
import babel from 'rollup-plugin-babel';
Expand Down Expand Up @@ -105,10 +106,13 @@ async function createRollupConfig({
extensions,
presets: [
[babelPresetEnv, { bugfixes: true, targets: { node: nodeTarget } }],
],
plugins: [
[
babelPresetTypescript,
babelPluginTransformTypeScript,
{ allowDeclareFields: true, onlyRemoveTypeImports: true },
],
babelPluginClassProperties,
],
}),
compress &&
Expand Down Expand Up @@ -199,6 +203,7 @@ async function createTypes({

interface BundlerOptions {
compress: boolean;
external?: string[];
input: string;
nodeTarget: string;
outputDir: string;
Expand All @@ -208,6 +213,7 @@ interface BundlerOptions {

export async function bundler({
compress,
external = [],
input,
nodeTarget,
outputDir,
Expand Down Expand Up @@ -239,7 +245,8 @@ export async function bundler({
const entry = inputs[idx];

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

const options = await createRollupConfig({
Expand Down
2 changes: 2 additions & 0 deletions src/vendor.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
declare module '@babel/plugin-proposal-class-properties';
declare module '@babel/plugin-transform-typescript';
declare module '@babel/preset-env';
declare module '@babel/preset-typescript';
declare module 'rollup-plugin-babel';

0 comments on commit 8f38863

Please sign in to comment.