-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] Use webpack to bundle all code to a single file
- Loading branch information
Showing
33 changed files
with
368 additions
and
256 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
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,3 +1,12 @@ | ||
{ | ||
"presets": ["es2015-node4", "stage-2"] | ||
"plugins": [ | ||
["transform-object-rest-spread", {"useBuiltIns": true}] | ||
], | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": "6" | ||
} | ||
}] | ||
] | ||
} |
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 |
---|---|---|
|
@@ -13,3 +13,6 @@ node_modules | |
# Built vendor files | ||
/vendor | ||
!/vendor/README.md | ||
|
||
# Packed version of Sanity binary | ||
/bin/sanity |
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 +1,8 @@ | ||
src/ | ||
/src | ||
/test | ||
/.babelrc | ||
/.editorconfig | ||
/.eslintignore | ||
/.eslintrc | ||
/yarn.lock | ||
/package-lock.json |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,20 +1,20 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-var, no-console, no-process-exit, prefer-template */ | ||
|
||
/** | ||
* ┌────────────────┐ | ||
* │ │ | ||
* │ WEBPACK ENTRY │ | ||
* │ NO ES6 IN HERE │ | ||
* │ !NOT COMPILED! │ | ||
* │ │ | ||
* └────────────────┘ | ||
*/ | ||
|
||
var nodeVersion = Number(process.version.replace(/^v/i, '').split('.', 2)[0]) | ||
|
||
if (nodeVersion < 6) { | ||
console.error('ERROR: Node.js version 6 or higher required. You are running ' + process.version) | ||
process.exit(1) | ||
} else { | ||
require('../lib/cli')() | ||
} | ||
|
||
var path = require('path') | ||
var runCli = require('../lib/cli') | ||
runCli(path.join(__dirname, '..')) |
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,13 @@ | ||
/* eslint-disable space-before-function-paren */ | ||
module.exports = function(content) { | ||
if (this.cacheable) { | ||
this.cacheable() | ||
} | ||
|
||
this.value = content | ||
|
||
const nonLazy = content.replace(/ = lazyRequire\(/g, ' = () => require(') | ||
const withoutLazy = nonLazy.replace(/\n.*?lazyRequire\d* = .*?\n/g, '') | ||
|
||
return withoutLazy | ||
} |
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,89 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-console, no-process-exit, no-sync */ | ||
const fse = require('fs-extra') | ||
const path = require('path') | ||
const webpack = require('webpack') | ||
const klawSync = require('klaw-sync') | ||
|
||
const lazyLoader = require.resolve('./lazy-loader') | ||
const shebangLoader = require.resolve('./shebang-loader') | ||
const basedir = path.join(__dirname, '..') | ||
|
||
// Make sure there are no native modules | ||
const isBinding = file => path.basename(file.path) === 'binding.gyp' | ||
const bindings = klawSync(basedir, {nodir: true, filter: isBinding}) | ||
|
||
if (bindings.length > 0) { | ||
console.error('Eek! Found native module at:') | ||
bindings.forEach(file => console.error(file.path)) | ||
process.exit(1) | ||
} | ||
|
||
const babelRc = JSON.parse(fse.readFileSync(path.join(basedir, '.babelrc'), 'utf8')) | ||
|
||
// Use the real node __dirname and __filename in order to get Yarn's source | ||
// files on the user's system. See constants.js | ||
const nodeOptions = { | ||
__filename: false, | ||
__dirname: false | ||
} | ||
|
||
const compiler = webpack({ | ||
entry: { | ||
sanity: path.join(basedir, 'bin/sanity.js') | ||
}, | ||
output: { | ||
filename: 'sanity', | ||
path: path.join(basedir, 'bin'), | ||
libraryTarget: 'commonjs2' | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: [{loader: 'babel-loader', options: babelRc}] | ||
}, | ||
{ | ||
test: /node_modules[/\\]rc[/\\]/, | ||
use: [{loader: shebangLoader}] | ||
}, | ||
{ | ||
test: /node_modules[/\\]update-notifier[/\\].*\.js$/, | ||
use: [{loader: lazyLoader}] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.NoEmitOnErrorsPlugin(), | ||
new webpack.BannerPlugin({ | ||
banner: '#!/usr/bin/env node', | ||
raw: true | ||
}), | ||
new webpack.DefinePlugin({ | ||
__SANITY_IS_BUNDLED__: JSON.stringify(true), | ||
|
||
// Workaround for rc module console.logging if module.parent does not exist | ||
'module.parent': JSON.stringify({}) | ||
}) | ||
], | ||
target: 'node', | ||
node: nodeOptions | ||
}) | ||
|
||
compiler.run((err, stats) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
if (stats.compilation.errors.length > 0) { | ||
console.error(stats.compilation.errors) | ||
process.exit(1) | ||
} | ||
|
||
// Make the file executable | ||
const outputPath = path.join(basedir, 'bin', 'sanity') | ||
fse.chmodSync(outputPath, 0o755) | ||
|
||
console.log('Done packing.') | ||
}) |
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,15 @@ | ||
/* eslint-disable space-before-function-paren */ | ||
module.exports = function(content) { | ||
if (this.cacheable) { | ||
this.cacheable() | ||
} | ||
|
||
this.value = content | ||
let source = content | ||
|
||
if (typeof source === 'string' && /^\s*#!/.test(source)) { | ||
source = source.replace(/^\s*#![^\n\r]*[\r\n]/, '') | ||
} | ||
|
||
return source | ||
} |
Oops, something went wrong.