shuvi 0.0.1-rc.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ declare type Command = (argv: string[]) => void;
2
+ declare const args: string[];
3
+ declare const cmdPath: string, commandArgs: string[];
4
+ declare const mod: any;
5
+ declare const cmd: Command;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // fix yarn link with react hooks
3
+ if (process.env.SHUVI__SECRET_FIX_LOCAL_RESOLVE) {
4
+ const path = require('path');
5
+ const resolveNodeModule = (req) => path.resolve(__dirname, '../../../../node_modules', req);
6
+ const BuiltinModule = require('module');
7
+ // Guard against poorly mocked module constructors
8
+ const Module = module.constructor.length > 1 ? module.constructor : BuiltinModule;
9
+ const oldResolveFilename = Module._resolveFilename;
10
+ Module._resolveFilename = function (request, parentModule, isMain, options) {
11
+ let redirectdRequest = request;
12
+ // make sure these packages are resolved into project/node_modules/
13
+ // this only works on server side
14
+ if (['react', 'react-dom'].includes(request)) {
15
+ redirectdRequest = resolveNodeModule(request);
16
+ }
17
+ return oldResolveFilename.call(this, redirectdRequest, parentModule, isMain, options);
18
+ };
19
+ }
20
+ const args = process.argv.slice(2);
21
+ const [cmdPath, ...commandArgs] = args.length ? args : ['dev'];
22
+ const mod = require(cmdPath);
23
+ const cmd = mod.default || mod;
24
+ cmd(commandArgs);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/cli/cli.js ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = __importDefault(require("commander"));
8
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
9
+ //@ts-ignore
10
+ const package_json_1 = __importDefault(require("../../package.json"));
11
+ const Commands = ['dev', 'build', 'serve', 'inspect'];
12
+ // must be before .parse()
13
+ commander_1.default.on('--help', () => {
14
+ console.log('');
15
+ console.log('Avaliable cmds:');
16
+ console.log(` ${Commands.join(', ')}`);
17
+ });
18
+ commander_1.default.name('shuvi').version(package_json_1.default.version).usage('<cmd> [options]');
19
+ const args = process.argv.slice(2);
20
+ const [cmd, ...commandArgs] = args.length ? args : ['dev'];
21
+ if (!Commands.includes(cmd)) {
22
+ console.error('Unknown command "' + cmd + '".');
23
+ commander_1.default.outputHelp();
24
+ process.exit(1);
25
+ }
26
+ const nodeEnv = cmd === 'dev' ? 'development' : 'production';
27
+ const result = cross_spawn_1.default.sync('node', [
28
+ require.resolve('./agent'),
29
+ require.resolve('./cmds/' + cmd),
30
+ ...commandArgs
31
+ ], {
32
+ stdio: 'inherit',
33
+ env: Object.assign(Object.assign({}, process.env), { NODE_ENV: nodeEnv })
34
+ });
35
+ if (result.signal) {
36
+ if (result.signal === 'SIGKILL') {
37
+ console.log('The build failed because the process exited too early. ' +
38
+ 'This probably means the system ran out of memory or someone called ' +
39
+ '`kill -9` on the process.');
40
+ }
41
+ else if (result.signal === 'SIGTERM') {
42
+ console.log('The build failed because the process exited too early. ' +
43
+ 'Someone might have called `kill` or `killall`, or the system could ' +
44
+ 'be shutting down.');
45
+ }
46
+ process.exit(1);
47
+ }
48
+ process.exit(result.status);
@@ -0,0 +1 @@
1
+ export default function main(argv: string[]): Promise<void>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = __importDefault(require("commander"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const build_1 = require("@shuvi/service/lib/cli/build");
18
+ //@ts-ignore
19
+ const package_json_1 = __importDefault(require("../../../package.json"));
20
+ const utils_1 = require("../utils");
21
+ const cliConfigMap = {
22
+ analyze: 'analyze',
23
+ publicPath: 'publicPath',
24
+ routerHistory: 'router.history',
25
+ target(config) {
26
+ config.ssr = false;
27
+ }
28
+ };
29
+ function main(argv) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ commander_1.default
32
+ .name(package_json_1.default.name)
33
+ .usage(`build [dir] [options]`)
34
+ .helpOption()
35
+ .option('--config <file>', 'path to config file')
36
+ .option('--public-path <url>', 'specify the asset prefix. eg: https://some.cdn.com')
37
+ .option('--target <target>', 'specify the app output target. eg: spa')
38
+ .option('--router-history <history>', "specify the hisotry type. 'browser' or 'hash'")
39
+ .option('--analyze', 'generate html file to help analyze webpack bundle')
40
+ .option('--config-overrides [json]', 'config overrides json')
41
+ .parse(argv, { from: 'user' });
42
+ const cwd = utils_1.getProjectDir(commander_1.default);
43
+ const config = utils_1.getConfigFromCli(commander_1.default, cliConfigMap);
44
+ try {
45
+ yield build_1.build({
46
+ cwd,
47
+ config,
48
+ configFile: commander_1.default.config && path_1.default.resolve(cwd, commander_1.default.config),
49
+ target: commander_1.default.target
50
+ });
51
+ console.log('Build successfully!');
52
+ }
53
+ catch (error) {
54
+ console.error('Failed to build.\n');
55
+ console.error(error.message);
56
+ process.exit(1);
57
+ }
58
+ });
59
+ }
60
+ exports.default = main;
@@ -0,0 +1 @@
1
+ export default function main(argv: string[]): Promise<void>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = __importDefault(require("commander"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const service_1 = require("@shuvi/service");
18
+ //@ts-ignore
19
+ const package_json_1 = __importDefault(require("../../../package.json"));
20
+ const utils_1 = require("../utils");
21
+ function main(argv) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ commander_1.default
24
+ .name(package_json_1.default.name)
25
+ .usage(`dev [dir] [options]`)
26
+ .helpOption()
27
+ .option('--config <file>', 'path to config file')
28
+ .option('--host <host>', 'specify host')
29
+ .option('--port <port>', 'specify port')
30
+ .option('--config-overrides [json]', 'config overrides json')
31
+ .parse(argv, { from: 'user' });
32
+ const cwd = utils_1.getProjectDir(commander_1.default);
33
+ const port = Number(commander_1.default.port) || 3000;
34
+ const host = commander_1.default.host || 'localhost';
35
+ const config = utils_1.getConfigFromCli(commander_1.default);
36
+ const shuviApp = service_1.shuvi({
37
+ dev: true,
38
+ cwd,
39
+ config,
40
+ configFile: commander_1.default.config && path_1.default.resolve(cwd, commander_1.default.config)
41
+ });
42
+ try {
43
+ console.log('Starting the development server...');
44
+ yield shuviApp.listen(port, host);
45
+ const localUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;
46
+ console.log(`Ready on ${localUrl}`);
47
+ }
48
+ catch (err) {
49
+ if (err.code === 'EADDRINUSE') {
50
+ let errorMessage = `Port ${port} is already in use.`;
51
+ errorMessage += '\nUse `--port` to specify some other port.';
52
+ // tslint:disable-next-line
53
+ console.error(errorMessage);
54
+ }
55
+ else {
56
+ // tslint:disable-next-line
57
+ console.error(err);
58
+ }
59
+ process.nextTick(() => process.exit(1));
60
+ }
61
+ });
62
+ }
63
+ exports.default = main;
@@ -0,0 +1 @@
1
+ export default function main(argv: string[]): Promise<void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const util_1 = require("util");
16
+ const path_1 = __importDefault(require("path"));
17
+ const commander_1 = __importDefault(require("commander"));
18
+ const cli_highlight_1 = require("cli-highlight");
19
+ const chalk_1 = __importDefault(require("@shuvi/utils/lib/chalk"));
20
+ const service_1 = require("@shuvi/service");
21
+ const bundler_1 = require("@shuvi/service/lib/bundler/bundler");
22
+ const utils_1 = require("../utils");
23
+ //@ts-ignore
24
+ const package_json_1 = __importDefault(require("../../../package.json"));
25
+ function main(argv) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ commander_1.default
28
+ .name(package_json_1.default.name)
29
+ .description('inspect internal webpack config')
30
+ .usage('inspect [options] [...paths]')
31
+ .helpOption()
32
+ .option('--config <file>', 'path to config file')
33
+ .option('--config-overrides [json]', 'config overrides json')
34
+ .option('--mode <mode>', 'specify env mode (default: development)')
35
+ .option('--verbose', 'show full webpack config')
36
+ .parse(argv, { from: 'user' });
37
+ const cwd = utils_1.getProjectDir(commander_1.default);
38
+ const mode = ['development', 'production'].includes(commander_1.default.mode)
39
+ ? commander_1.default.mode
40
+ : 'development';
41
+ Object.assign(process.env, {
42
+ NODE_ENV: mode
43
+ });
44
+ const config = utils_1.getConfigFromCli(commander_1.default);
45
+ const api = yield service_1.getApi({
46
+ cwd,
47
+ config,
48
+ configFile: commander_1.default.config && path_1.default.resolve(cwd, commander_1.default.config),
49
+ mode,
50
+ phase: 'PHASE_INSPECT_WEBPACK'
51
+ });
52
+ const bundler = bundler_1.getBundler(api);
53
+ const configs = yield bundler.resolveWebpackConfig();
54
+ configs.forEach(({ name, config }) => {
55
+ console.log(chalk_1.default.cyan.bold(`${name} webpack config`));
56
+ const configString = util_1.inspect(config, { depth: commander_1.default.verbose ? 10 : 2 });
57
+ if (process.env.__DISABLE_HIGHLIGHT__ === 'true') {
58
+ console.log(configString);
59
+ }
60
+ else {
61
+ console.log(cli_highlight_1.highlight(configString, { language: 'js' }));
62
+ }
63
+ });
64
+ });
65
+ }
66
+ exports.default = main;
@@ -0,0 +1 @@
1
+ export default function main(argv: string[]): Promise<void>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = __importDefault(require("commander"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const service_1 = require("@shuvi/service");
18
+ //@ts-ignore
19
+ const package_json_1 = __importDefault(require("../../../package.json"));
20
+ const utils_1 = require("../utils");
21
+ function main(argv) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ commander_1.default
24
+ .name(package_json_1.default.name)
25
+ .usage(`serve [dir] [options]`)
26
+ .helpOption()
27
+ .option('--config <file>', 'path to config file')
28
+ .option('--host <host>', 'specify host')
29
+ .option('--port <port>', 'specify port')
30
+ .option('--config-overrides [json]', 'config overrides json')
31
+ .parse(argv, { from: 'user' });
32
+ const cwd = utils_1.getProjectDir(commander_1.default);
33
+ const port = Number(commander_1.default.port) || 3000;
34
+ const host = commander_1.default.host || 'localhost';
35
+ const config = utils_1.getConfigFromCli(commander_1.default);
36
+ const shuviApp = service_1.shuvi({
37
+ cwd,
38
+ config,
39
+ configFile: commander_1.default.config && path_1.default.resolve(cwd, commander_1.default.config)
40
+ });
41
+ try {
42
+ yield shuviApp.listen(port, host);
43
+ console.log(`Ready on http://${host}:${port}`);
44
+ }
45
+ catch (err) {
46
+ console.error(err);
47
+ process.exit(1);
48
+ }
49
+ });
50
+ }
51
+ exports.default = main;
@@ -0,0 +1,4 @@
1
+ import { CommanderStatic } from 'commander';
2
+ import { IConfig } from '@shuvi/service';
3
+ export declare function getProjectDir(cmd: CommanderStatic | Record<string, any>): string;
4
+ export declare function getConfigFromCli(cliOptions: Record<string, any>, cliOptionsKeyMap?: Record<string, string | ((config: any, optionValue: any) => void)>): IConfig;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = require("fs");
7
+ const path_1 = __importDefault(require("path"));
8
+ function getProjectDir(cmd) {
9
+ const dir = path_1.default.resolve(cmd.args[0] || '.');
10
+ if (!fs_1.existsSync(dir)) {
11
+ console.error(`> No such directory exists as the project root: ${dir}`);
12
+ cmd.outputHelp();
13
+ process.exit(1);
14
+ }
15
+ return dir;
16
+ }
17
+ exports.getProjectDir = getProjectDir;
18
+ function set(obj, path, value) {
19
+ const segments = path.split('.');
20
+ const final = segments.pop();
21
+ for (var i = 0; i < segments.length; i++) {
22
+ if (!obj) {
23
+ return;
24
+ }
25
+ obj = obj[segments[i]];
26
+ }
27
+ obj[final] = value;
28
+ }
29
+ function getConfigFromCli(cliOptions, cliOptionsKeyMap = {}) {
30
+ const config = {};
31
+ Object.keys(cliOptionsKeyMap).forEach(key => {
32
+ if (typeof cliOptions[key] !== 'undefined') {
33
+ const mappedKeyOrFunction = cliOptionsKeyMap[key];
34
+ const cliOptionValue = cliOptions[key];
35
+ if (typeof mappedKeyOrFunction === 'function') {
36
+ mappedKeyOrFunction(config, cliOptionValue);
37
+ }
38
+ else {
39
+ set(config, mappedKeyOrFunction, cliOptionValue);
40
+ }
41
+ }
42
+ });
43
+ try {
44
+ const { configOverrides } = cliOptions;
45
+ if (configOverrides) {
46
+ const overrides = JSON.parse(configOverrides);
47
+ Object.assign(config, overrides);
48
+ }
49
+ }
50
+ catch (err) {
51
+ console.error(err);
52
+ }
53
+ return config;
54
+ }
55
+ exports.getConfigFromCli = getConfigFromCli;
package/lib/index.d.ts ADDED
File without changes
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "shuvi",
3
+ "version": "0.0.1-rc.33",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/shuvijs/shuvi.git",
7
+ "directory": "packages/shuvi"
8
+ },
9
+ "author": "liximomo",
10
+ "license": "MIT",
11
+ "main": "./lib/index.js",
12
+ "bin": {
13
+ "shuvi": "./lib/cli/cli.js"
14
+ },
15
+ "files": [
16
+ "lib",
17
+ "types"
18
+ ],
19
+ "scripts": {
20
+ "dev": "tsc -p tsconfig.build.json -w",
21
+ "prebuild": "rimraf lib",
22
+ "build": "tsc -p tsconfig.build.json"
23
+ },
24
+ "engines": {
25
+ "node": ">= 12.0.0"
26
+ },
27
+ "dependencies": {
28
+ "@shuvi/platform-mp": "^0.0.1-rc.33",
29
+ "@shuvi/platform-web": "^0.0.1-rc.33",
30
+ "@shuvi/service": "^0.0.1-rc.33",
31
+ "@shuvi/shared": "0.0.1-rc.32",
32
+ "@shuvi/utils": "^0.0.1-rc.33",
33
+ "cli-highlight": "^2.1.9",
34
+ "commander": "5.1.0",
35
+ "cross-spawn": "7.0.3",
36
+ "dotenv": "8.2.0",
37
+ "dotenv-expand": "5.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/cross-spawn": "6.0.1",
41
+ "@types/dotenv": "8.2.0"
42
+ },
43
+ "gitHead": "ee2abab3c102f68450cf1fb6b2c833d5a59fb0c7"
44
+ }