forked from vercel/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix .node loading issue on windows (vercel#1135)
- Loading branch information
1 parent
211da6e
commit dccee8a
Showing
6 changed files
with
171 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
lib-es5 | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package-lock.json | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable no-unused-vars */ | ||
var canvas = require('canvas'); | ||
console.log('42'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const utils = require('../utils.js'); | ||
|
||
assert(__dirname === process.cwd()); | ||
|
||
const target = process.argv[2] || 'host'; | ||
const input = './package.json'; | ||
const output = './test-output.exe'; | ||
|
||
console.log('target = ', target); | ||
|
||
// remove any possible left-over | ||
utils.vacuum.sync('./node_modules'); | ||
|
||
// npm instal -g node-pre-gyp | ||
utils.exec.sync('npm install -g node-pre-gyp'); | ||
|
||
// launch `npm install` | ||
const npmlog = utils.spawn.sync( | ||
path.join( | ||
path.dirname(process.argv[0]), | ||
'npx' + (process.platform === 'win32' ? '.cmd' : '') | ||
), | ||
['npm', 'install'], | ||
{ cwd: path.dirname(output), expect: 0 } | ||
); | ||
console.log('npm log :', npmlog); | ||
|
||
// verify that we have the .pnpm folder and a symlinks module in node_modules | ||
assert(fs.lstatSync(path.join(__dirname, 'node_modules/canvas')).isDirectory()); | ||
assert( | ||
fs.lstatSync(path.join(__dirname, 'node_modules/canvas/build')).isDirectory() | ||
); | ||
assert( | ||
fs | ||
.lstatSync(path.join(__dirname, 'node_modules/canvas/build/Release')) | ||
.isDirectory() | ||
); | ||
assert( | ||
fs | ||
.lstatSync( | ||
path.join(__dirname, 'node_modules/canvas/build/Release/canvas.node') | ||
) | ||
.isFile() | ||
); | ||
|
||
utils.pkg.sync(['--target', target, '--debug', '--output', output, input]); | ||
|
||
// check that produced executable is running and produce the expected output. | ||
const log = utils.spawn.sync(output, [], { | ||
cwd: path.dirname(output), | ||
expect: 0, | ||
}); | ||
assert(log === '42\n'); | ||
|
||
// clean up | ||
utils.vacuum.sync(output); | ||
utils.vacuum.sync('./node_modules'); | ||
utils.vacuum.sync('./package-lock.json'); | ||
|
||
console.log('OK'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "pkg_issue_1335", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"bin": "./index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"pkg42": "npx pkg -t host package.json" | ||
}, | ||
"pkg": { | ||
"scripts": "index.js", | ||
"assets": "node_modules/canvas/build/Release/*", | ||
"outputPath": "dist2" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"canvas": "^2.7.0" | ||
} | ||
} |