Skip to content

Commit

Permalink
monkey-patch preact
Browse files Browse the repository at this point in the history
  • Loading branch information
zavr-1 committed May 14, 2019
1 parent 584fbec commit dda3d67
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"files": [
"build",
"builtin-modules",
"externs"
"externs",
"preact"
],
"bin": {
"depack": "build/depack.js",
Expand Down
1 change: 1 addition & 0 deletions preact/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@externs/preact'
4 changes: 4 additions & 0 deletions preact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "preact",
"module": "index.js"
}
26 changes: 24 additions & 2 deletions src/depack.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env node
import {
_source, _advanced, _noSourcemap, _debug, _language_in, _language_out, _level, _noWarnings, _output, _prettyPrint, _verbose, _help, _version, _argv,
_iife, _preact, _temp, // bundle
_iife, _preact, _temp, _external, // bundle
_compile, _library, _noStrict, // compile
} from './get-args'
import { GOOGLE_CLOSURE_COMPILER, run, Bundle, Compile, getOptions, getCompilerVersion, getOutput } from '@depack/depack'
import resolveDependency from 'resolve-dependency'
import { renameSync, symlinkSync, unlinkSync } from 'fs'
import { resolve } from 'path'
import { c } from 'erte'
import usage from './usage'

if (_help) {
Expand Down Expand Up @@ -48,6 +51,15 @@ if (_help) {
library: _library,
}, runOptions, options)
}
if (_external) {
console.error(c('monkey-patching preact', 'yellow'))
renameSync('node_modules/preact', 'node_modules/_preact')
symlinkSync(resolve(__dirname, '../preact'), 'node_modules/preact')

process.on('SIGINT', () => {})
process.on('SIGTERM', () => {})
process.on('beforeExit', restorePreact)
}
await Bundle({
src,
tempDir: _temp,
Expand All @@ -56,4 +68,14 @@ if (_help) {
} catch (error) {
process.env['DEBUG'] ? console.log(error.stack) : console.log(error.message)
}
})()
})()

const restorePreact = () => {
console.error(c('cleaning up preact patch', 'yellow'))
try {
unlinkSync('node_modules/preact')
renameSync('node_modules/_preact', 'node_modules/preact')
} catch (err) {
//
}
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
static-analysis "^1.7.1"

"@depack/detect@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@depack/detect/-/detect-1.0.2.tgz#79992a37e23bfa5747b328d929f378fba6233d14"
integrity sha512-kSE1k+qvBgnfKwU5jVnEOoBY/tYxBz6o1lxzyTqLG8fezY1aeRywq7E91B/jdJ4FMu3HA8osCSG13zw8V76mUg==
version "1.1.0"
resolved "https://registry.yarnpkg.com/@depack/detect/-/detect-1.1.0.tgz#e5e5cbd2c7f68d689363f4b4a7179a2918d45ff3"
integrity sha512-t6OBa7LsPNhBFDcEN1V6S3nIQp0t3rB2OfTa/UiV1jCyeI+AEmy4iwhlkgv0pdMEs+gzgwnQQ/6bwQGI6+89lA==
dependencies:
mismatch "^1.1.1"
mismatch "^1.2.0"

"@depack/externs@^1.4.1":
version "1.4.1"
Expand Down Expand Up @@ -283,7 +283,7 @@ makepromise@^3.0.3, makepromise@^3.1.0:
dependencies:
erotic "^2.1.0"

mismatch@^1.1.1, mismatch@^1.2.0:
mismatch@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mismatch/-/mismatch-1.2.0.tgz#3f5021861e8084e36a14c2c1f9489941cd18f790"
integrity sha512-kuw1k8ZHS+12fBVAVOBXMBJBXcNGnByFTJIDzH4W4v84OocejZ/qzxmT4ll9CLX5OD23NXr+NvrQDus0BsQ8xw==
Expand Down

0 comments on commit dda3d67

Please sign in to comment.