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

v6 dev #179

Merged
merged 2 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions dist/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var path = require('path');
var path = _interopDefault(require('path'));
var readPkgUp = _interopDefault(require('read-pkg-up'));
var rollup = require('rollup');
var cjsPlugin = _interopDefault(require('rollup-plugin-commonjs'));
Expand All @@ -16,7 +16,7 @@ var hashbang = _interopDefault(require('@ianwalter/rollup-plugin-hashbang'));

async function dist (options) {
// Read modules package.json.
const { package: pkg, path: path$1 } = await readPkgUp();
const { package: pkg, path: projectPath } = await readPkgUp();

// TODO: comment
const hasFormat = options.cjs || options.esm || options.browser;
Expand All @@ -25,8 +25,9 @@ async function dist (options) {
// Deconstruct options and set defaults if necessary.
let {
name = options.name || npmShortName(pkg.name),
input = options.input || path.resolve(path.join(path.dirname(path$1), 'index.js')),
output = options.output || path.join(path.dirname(path$1), 'dist'),
input = options.input ||
path.resolve(path.join(path.dirname(projectPath), 'index.js')),
output = options.output || path.join(path.dirname(projectPath), 'dist'),
cjs = getFormat(options.cjs, pkg.main),
esm = getFormat(options.esm, pkg.module),
browser = getFormat(options.browser, pkg.browser)
Expand Down Expand Up @@ -59,10 +60,11 @@ async function dist (options) {
inlineDeps = inline.split(',');
nodeResolve = nodeResolvePlugin({ only: inlineDeps });
}
const byIsNotInlineDep = dep => inlineDeps.indexOf(dep) === -1;
const externalDeps = [...builtinModules, ...deps.filter(byIsNotInlineDep)];
const externalModules = deps.filter(dep => inlineDeps.indexOf(dep) === -1);
const externalDeps = [...builtinModules, ...externalModules];
const external = id => (
externalDeps.includes(id) || externalDeps.some(n => id.includes(n + '/'))
externalDeps.includes(id) ||
externalModules.some(external => id.includes(external + path.sep))
);

// Set the default babel config.
Expand Down
38 changes: 20 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join, resolve, extname } from 'path'
import path from 'path'
import readPkgUp from 'read-pkg-up'
import { rollup } from 'rollup'
import cjsPlugin from 'rollup-plugin-commonjs'
Expand All @@ -12,7 +12,7 @@ import hashbang from '@ianwalter/rollup-plugin-hashbang'

export default async function dist (options) {
// Read modules package.json.
const { package: pkg, path } = await readPkgUp()
const { package: pkg, path: projectPath } = await readPkgUp()

// TODO: comment
const hasFormat = options.cjs || options.esm || options.browser
Expand All @@ -21,8 +21,9 @@ export default async function dist (options) {
// Deconstruct options and set defaults if necessary.
let {
name = options.name || npmShortName(pkg.name),
input = options.input || resolve(join(dirname(path), 'index.js')),
output = options.output || join(dirname(path), 'dist'),
input = options.input ||
path.resolve(path.join(path.dirname(projectPath), 'index.js')),
output = options.output || path.join(path.dirname(projectPath), 'dist'),
cjs = getFormat(options.cjs, pkg.main),
esm = getFormat(options.esm, pkg.module),
browser = getFormat(options.browser, pkg.browser)
Expand All @@ -36,7 +37,7 @@ export default async function dist (options) {
// Import plugins file if specified.
let plugins = []
if (typeof options.plugins === 'string') {
const input = resolve(options.plugins)
const input = path.resolve(options.plugins)
const external = Object.keys(pkg.devDependencies || {})
const { generate } = await rollup({ input, external })
const { output: [{ code }] } = await generate({ format: 'cjs' })
Expand All @@ -55,10 +56,11 @@ export default async function dist (options) {
inlineDeps = inline.split(',')
nodeResolve = nodeResolvePlugin({ only: inlineDeps })
}
const byIsNotInlineDep = dep => inlineDeps.indexOf(dep) === -1
const externalDeps = [...builtinModules, ...deps.filter(byIsNotInlineDep)]
const externalModules = deps.filter(dep => inlineDeps.indexOf(dep) === -1)
const externalDeps = [...builtinModules, ...externalModules]
const external = id => (
externalDeps.includes(id) || externalDeps.some(n => id.includes(n + '/'))
externalDeps.includes(id) ||
externalModules.some(external => id.includes(external + path.sep))
)

// Set the default babel config.
Expand Down Expand Up @@ -104,16 +106,16 @@ export default async function dist (options) {
let esmCode = (esm || browser) ? esmBundle.output[0].code : undefined

// Determine the output file paths.
const dir = extname(output) ? dirname(output) : output
const cjsPath = typeof cjs === 'string' && extname(cjs)
? resolve(cjs)
: join(dir, `${name}.js`)
const esmPath = typeof esm === 'string' && extname(esm)
? resolve(esm)
: join(dir, `${name}.m.js`)
const browserPath = typeof browser === 'string' && extname(browser)
? resolve(browser)
: join(dir, `${name}.browser.js`)
const dir = path.extname(output) ? path.dirname(output) : output
const cjsPath = typeof cjs === 'string' && path.extname(cjs)
? path.resolve(cjs)
: path.join(dir, `${name}.js`)
const esmPath = typeof esm === 'string' && path.extname(esm)
? path.resolve(esm)
: path.join(dir, `${name}.m.js`)
const browserPath = typeof browser === 'string' && path.extname(browser)
? path.resolve(browser)
: path.join(dir, `${name}.browser.js`)

// Return an object with the properties that use the file path as the key and
// the source code as the value.
Expand Down