Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from ianwalter/fix-48
Browse files Browse the repository at this point in the history
Inlining ky instead of promise-complete
  • Loading branch information
Ian Walter authored Feb 12, 2019
2 parents 4dab4e7 + 7b95cbf commit ae5d415
Show file tree
Hide file tree
Showing 11 changed files with 1,181 additions and 73 deletions.
12 changes: 10 additions & 2 deletions dist/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var cjsPlugin = _interopDefault(require('rollup-plugin-commonjs'));
var nodeResolvePlugin = _interopDefault(require('rollup-plugin-node-resolve'));
var jsonPlugin = _interopDefault(require('rollup-plugin-json'));
var npmShortName = _interopDefault(require('@ianwalter/npm-short-name'));
var babel = _interopDefault(require('rollup-plugin-babel'));
var babelPlugin = _interopDefault(require('rollup-plugin-babel'));
var requireFromString = _interopDefault(require('require-from-string'));

async function dist (options) {
Expand Down Expand Up @@ -69,6 +69,14 @@ async function dist (options) {
...dependencies.filter(d => inlineDependencies.indexOf(d) === -1)
];

// Set the default babel config.
const babelConfig = {
runtimeHelpers: true,
externalHelpers: true,
babelrc: false,
...pkg.babel
};

// Determine which Rollup plugins should be used.
const rollupPlugins = [
// Allows dependencies to be bundled:
Expand All @@ -78,7 +86,7 @@ async function dist (options) {
// Allows JSON to be imported:
jsonPlugin(),
// Allows source to be transpiled with babel:
...(options.babel ? [babel({ runtimeHelpers: true })] : []),
...(options.babel ? [babelPlugin(babelConfig)] : []),
// Allow users to pass in their own rollup plugins:
...plugins
];
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cjsPlugin from 'rollup-plugin-commonjs'
import nodeResolvePlugin from 'rollup-plugin-node-resolve'
import jsonPlugin from 'rollup-plugin-json'
import npmShortName from '@ianwalter/npm-short-name'
import babel from 'rollup-plugin-babel'
import babelPlugin from 'rollup-plugin-babel'
import requireFromString from 'require-from-string'

export default async function dist (options) {
Expand Down Expand Up @@ -65,6 +65,14 @@ export default async function dist (options) {
...dependencies.filter(d => inlineDependencies.indexOf(d) === -1)
]

// Set the default babel config.
const babelConfig = {
runtimeHelpers: true,
externalHelpers: true,
babelrc: false,
...pkg.babel
}

// Determine which Rollup plugins should be used.
const rollupPlugins = [
// Allows dependencies to be bundled:
Expand All @@ -74,7 +82,7 @@ export default async function dist (options) {
// Allows JSON to be imported:
jsonPlugin(),
// Allows source to be transpiled with babel:
...(options.babel ? [babel({ runtimeHelpers: true })] : []),
...(options.babel ? [babelPlugin(babelConfig)] : []),
// Allow users to pass in their own rollup plugins:
...plugins
]
Expand Down
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test": "ava"
},
"dependencies": {
"@babel/core": "^7.2.2",
"@ianwalter/npm-short-name": "^1.0.0",
"@ianwalter/promise-complete": "^3.0.1",
"chalk": "^2.4.2",
Expand All @@ -53,6 +54,8 @@
"rollup-plugin-node-resolve": "^4.0.0"
},
"devDependencies": {
"@babel/runtime": "^7.3.1",
"@ianwalter/babel-preset-lib": "^1.1.0",
"@ianwalter/execa-helper": "^1.0.0",
"ava": "^1.2.1",
"common-tags": "^1.8.0",
Expand All @@ -63,11 +66,21 @@
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"ky": "^0.8.0",
"np": "^3.1.0",
"postcss": "^7.0.14",
"rollup-plugin-vue": "^4.7.1",
"vue-template-compiler": "^2.6.4"
},
"babel": {
"env": {
"test": {
"presets": [
"@ianwalter/lib"
]
}
}
},
"eslintConfig": {
"root": true,
"extends": [
Expand Down
3 changes: 2 additions & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import test from 'ava'
import execaHelper from '@ianwalter/execa-helper'

const withCli = execaHelper('./cli.js')
const withCnt = execaHelper('./cli.js', false)

test('cjs file not generated when --no-cjs passed', withCli, async (t, cli) => {
const input = 'test/fixtures/exportDefaultFunction.js'
Expand All @@ -12,7 +13,7 @@ test('cjs file not generated when --no-cjs passed', withCli, async (t, cli) => {
t.snapshot(readFileSync(esm, 'utf8'))
})

test('dist file is transpiled when --babel passed', withCli, async (t, cli) => {
test('dist file is transpiled when --babel passed', withCnt, async (t, cli) => {
const input = 'test/fixtures/exportDefaultNewExpression.js'
const cjs = 'tmp/two.js'
const { stdout } = await cli('-i', input, '--cjs', cjs, '--babel')
Expand Down
4 changes: 2 additions & 2 deletions test/dist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ test('dist bundles specified imports with module into dist files', async t => {
const name = 'exportObjectWithImports'
const input = join(__dirname, `fixtures/${name}.js`)
const cjs = join(output, `${name}.js`)
const inline = '@ianwalter/promise-complete'
t.snapshot(await dist({ name, input, output, cjs, inline }))
const babel = true
t.snapshot(await dist({ name, input, output, cjs, inline: 'ky', babel }))
})
4 changes: 2 additions & 2 deletions test/fixtures/exportObjectWithImports.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import npmShortName from '@ianwalter/npm-short-name'
import promiseComplete from '@ianwalter/promise-complete'
import ky from 'ky'
import greeting from './exportDefaultFunction'

export {
npmShortName,
greeting,
promiseComplete
ky
}
8 changes: 7 additions & 1 deletion test/snapshots/cli.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ Generated by [AVA](https://ava.li).
`'use strict';␊
class SomeClass {}␊
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }␊
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck'));␊
var SomeClass = function SomeClass() {␊
_classCallCheck(this, SomeClass);␊
};␊
var exportDefaultNewExpression = new SomeClass();␊
Expand Down
Binary file modified test/snapshots/cli.test.js.snap
Binary file not shown.
Loading

0 comments on commit ae5d415

Please sign in to comment.