Skip to content

Commit

Permalink
3.1.0 drop fork() support
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jan 20, 2022
1 parent aea3fcb commit 571dcad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 34 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,6 @@ require('asar-node/lib/autorun/index')
import 'asar-node/dist/autorun-lookup.js' // 1KB minified
```

* `node_modules/asar-node/dist/fork.js`

`child_process.fork()` entry for bundlers. Copy it to your output path.

```js
// webpack.config.js
// copy node_modules/asar-node/dist/fork.js -> /path/to/fork.js
const webpack = require('webpack')

module.exports = {
plugins: [
new webpack.DefinePlugin({
ASAR_NODE_FORK_ENTRY: '/path/to/fork.js'
})
]
}
```

## Available APIs inside asar

- `require('original-fs')`
Expand All @@ -173,7 +155,6 @@ require('asar-node/lib/autorun/index')
- `fs.createReadStream`
- `child_process.execFile`
- `child_process.execFileSync`
- **`child_process.fork`** - Predefine `ASAR_NODE_FORK_ENTRY` if you are using bundler

## Note

Expand Down
10 changes: 5 additions & 5 deletions lib/child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const childProcess = require('child_process')

let registered = false

let oldFork
// let oldFork
let oldExecFile
let oldExecFileSync
let oldExec
let oldExecSync

function overwriteChildProcess () {
if (registered) return
oldFork = childProcess.fork
/* oldFork = childProcess.fork
childProcess.fork = function (modulePath, args, options) {
if (isAsarDisabled()) {
return oldFork.apply(this, arguments)
Expand All @@ -41,7 +41,7 @@ function overwriteChildProcess () {
path.resolve(modulePath),
...(args || [])
], options)
}
} */

oldExec = childProcess.exec
childProcess.exec = invokeWithNoAsar(oldExec)
Expand Down Expand Up @@ -111,8 +111,8 @@ function overwriteChildProcess () {
function cancel () {
if (!registered) return

childProcess.fork = oldFork
oldFork = undefined
// childProcess.fork = oldFork
// oldFork = undefined
childProcess.exec = oldExec
oldExec = undefined
childProcess.execSync = oldExecSync
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asar-node",
"version": "3.0.1",
"version": "3.1.0",
"description": "Enable require('./path/to/any-node-project.asar') & require('./path/to/any-node-project.asar/any/file'). Or just run asar-node ./path/to/any-node-project.asar",
"bin": {
"asar-node": "./bin/asar-node.js"
Expand Down
6 changes: 3 additions & 3 deletions script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ webpack([
createTarget({
'autorun-register': [path.join(__dirname, '../lib/autorun/register.js')]
}, {}, false),
createTarget({
fork: [path.join(__dirname, '../lib/fork.js')]
}, { ASAR_NODE_FORK_ENTRY: '__filename' }, false),
// createTarget({
// fork: [path.join(__dirname, '../lib/fork.js')]
// }, { ASAR_NODE_FORK_ENTRY: '__filename' }, false),
createTarget({
'asar-node': [path.join(__dirname, '../bin/asar-node.js')]
}, {}, true)
Expand Down
12 changes: 6 additions & 6 deletions spec/asar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ describe('asar package', function () {
});
});

describe('child_process.fork', function () {
/* describe('child_process.fork', function () {
it('opens a normal js file', function (done) {
const child = ChildProcess.fork(path.join(asarDir, 'a.asar', 'ping.js'));
Expand Down Expand Up @@ -1341,7 +1341,7 @@ describe('asar package', function () {
});
child.send(file);
});
});
}); */

describe('child_process.exec', function () {
const echo = path.join(asarDir, 'echo.asar', 'echo');
Expand Down Expand Up @@ -1544,7 +1544,7 @@ describe('asar package', function () {

describe('process.env.ELECTRON_NO_ASAR', function () {

it('disables asar support in forked processes', function (done) {
/* it('disables asar support in forked processes', function (done) {
const forked = ChildProcess.fork(path.join(__dirname, 'fixtures', 'module', 'no-asar.js'), [], {
env: {
ELECTRON_NO_ASAR: true
Expand All @@ -1559,7 +1559,7 @@ describe('asar package', function () {
done(e);
}
});
});
}); */

it('disables asar support in spawned processes', function (done) {
const spawned = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'no-asar.js')], {
Expand Down Expand Up @@ -1661,13 +1661,13 @@ describe('asar package', function () {
expect(stats.isFile()).to.be.true();
});

ifit(true)('is available in forked scripts', async function () {
/* ifit(true)('is available in forked scripts', async function () {
const child = ChildProcess.fork(path.join(fixtures, 'module', 'original-fs.js'));
const message = emittedOnce(child, 'message');
child.send('message');
const [msg] = await message;
expect(msg).to.equal('object');
});
}); */

it('can be used with streams', () => {
originalFs.createReadStream(path.join(asarDir, 'a.asar'));
Expand Down

0 comments on commit 571dcad

Please sign in to comment.