Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
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
29 changes: 19 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const defaultOptions = {
browserifyOptions: {
extensions: ['.js', '.jsx', '.coffee', '.cjsx'],
transform: [
[
require.resolve('./cjsxify'),
{},
],
[require.resolve('./cjsxify'), {}],
[
require.resolve('babelify'),
{
Expand All @@ -30,7 +27,9 @@ const defaultOptions = {
plugins: ['babel-plugin-add-module-exports'].map(require.resolve),
// babel-preset-env supports any JS that's stage-4, meaning it's
// completely finalized in the ECMA standard
presets: ['babel-preset-env', 'babel-preset-react'].map(require.resolve),
presets: ['babel-preset-env', 'babel-preset-react'].map(
require.resolve
),
},
],
],
Expand Down Expand Up @@ -61,8 +60,16 @@ const preprocessor = (options = {}) => {
log('received user options', options)

// allow user to override default options
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions)
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)
const browserifyOptions = Object.assign(
{},
defaultOptions.browserifyOptions,
options.browserifyOptions
)
const watchifyOptions = Object.assign(
{},
defaultOptions.watchifyOptions,
options.watchifyOptions
)

// we return function that accepts the arguments provided by
// the event 'file:preprocessor'
Expand Down Expand Up @@ -152,18 +159,20 @@ const preprocessor = (options = {}) => {
log(`update ${filePath}`)
// we overwrite the cached bundle promise, so on subsequent invocations
// it gets the latest bundle
const bundlePromise = bundles[filePath] = bundle()
.finally(() => {
const bundlePromise = bundle().finally(() => {
log(`- update finished for ${filePath}`)
file.emit('rerun')
})
bundles[filePath] = bundlePromise
// we suppress unhandled rejections so they don't bubble up to the
// unhandledRejection handler and crash the app. Cypress will eventually
// take care of the rejection when the file is requested
bundlePromise.suppressUnhandledRejections()
})

const bundlePromise = fs.ensureDirAsync(path.dirname(outputPath)).then(bundle)
const bundlePromise = fs
.ensureDirAsync(path.dirname(outputPath))
.then(bundle)

// cache the bundle promise, so it can be returned if this function
// is invoked again with the same filePath
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"ban": "ban",
"deps": "deps-ok && dependency-check --no-dev .",
"license": "license-checker --production --onlyunknown --csv",
"lint": "eslint --fix *.js",
"lint": "prettier-eslint --write '*.js'",
"secure": "nsp check",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"pretest": "npm run lint",
"test": "mocha",
"test-debug": "node --inspect --debug-brk ./node_modules/.bin/_mocha",
"test-watch": "chokidar '*.js' 'test/*.js' -c 'npm test'",
Expand All @@ -43,13 +44,14 @@
"deps-ok": "1.2.1",
"dont-crack": "1.2.1",
"eslint": "4.6.1",
"eslint-plugin-cypress-dev": "1.0.0",
"eslint-plugin-cypress-dev": "1.0.2",
"eslint-plugin-mocha": "4.11.0",
"github-post-release": "1.13.1",
"license-checker": "13.0.3",
"mocha": "3.5.0",
"mockery": "2.1.0",
"nsp": "2.7.0",
"prettier-eslint-cli": "4.4.0",
"semantic-release": "8.2.0",
"simple-commit-message": "3.3.1",
"sinon": "3.2.1",
Expand Down