@shuvi/toolpack 0.0.1-pre.1

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.
Files changed (65) hide show
  1. package/lib/babel/plugins/auto-css-modules.d.ts +7 -0
  2. package/lib/babel/plugins/auto-css-modules.js +24 -0
  3. package/lib/babel/plugins/jsx-pragma.d.ts +4 -0
  4. package/lib/babel/plugins/jsx-pragma.js +77 -0
  5. package/lib/babel/plugins/loadable-plugin.d.ts +24 -0
  6. package/lib/babel/plugins/loadable-plugin.js +105 -0
  7. package/lib/babel/plugins/optimize-hook-destructuring.d.ts +4 -0
  8. package/lib/babel/plugins/optimize-hook-destructuring.js +59 -0
  9. package/lib/babel/preset.d.ts +14 -0
  10. package/lib/babel/preset.js +106 -0
  11. package/lib/constants.d.ts +1 -0
  12. package/lib/constants.js +3 -0
  13. package/lib/utils/emptyComponent.d.ts +1 -0
  14. package/lib/utils/emptyComponent.js +7 -0
  15. package/lib/utils/forkTsCheckerWebpackPlugin.d.ts +4 -0
  16. package/lib/utils/forkTsCheckerWebpackPlugin.js +9 -0
  17. package/lib/utils/formatWebpackMessages.d.ts +5 -0
  18. package/lib/utils/formatWebpackMessages.js +91 -0
  19. package/lib/utils/hotDevClient/eventsource.d.ts +1 -0
  20. package/lib/utils/hotDevClient/eventsource.js +63 -0
  21. package/lib/utils/hotDevClient/index.d.ts +4 -0
  22. package/lib/utils/hotDevClient/index.js +304 -0
  23. package/lib/utils/verifyTypeScriptSetup.d.ts +5 -0
  24. package/lib/utils/verifyTypeScriptSetup.js +229 -0
  25. package/lib/webpack/config/base.d.ts +16 -0
  26. package/lib/webpack/config/base.js +236 -0
  27. package/lib/webpack/config/browser.d.ts +8 -0
  28. package/lib/webpack/config/browser.js +147 -0
  29. package/lib/webpack/config/index.d.ts +4 -0
  30. package/lib/webpack/config/index.js +9 -0
  31. package/lib/webpack/config/node.d.ts +7 -0
  32. package/lib/webpack/config/node.js +55 -0
  33. package/lib/webpack/config/parts/external.d.ts +4 -0
  34. package/lib/webpack/config/parts/external.js +91 -0
  35. package/lib/webpack/config/parts/helpers.d.ts +3 -0
  36. package/lib/webpack/config/parts/helpers.js +48 -0
  37. package/lib/webpack/config/parts/resolve.d.ts +1 -0
  38. package/lib/webpack/config/parts/resolve.js +10 -0
  39. package/lib/webpack/config/parts/style.d.ts +9 -0
  40. package/lib/webpack/config/parts/style.js +217 -0
  41. package/lib/webpack/loaders/export-global-loader.d.ts +7 -0
  42. package/lib/webpack/loaders/export-global-loader.js +26 -0
  43. package/lib/webpack/loaders/route-component-loader.d.ts +7 -0
  44. package/lib/webpack/loaders/route-component-loader.js +14 -0
  45. package/lib/webpack/loaders/shuvi-babel-loader.d.ts +1 -0
  46. package/lib/webpack/loaders/shuvi-babel-loader.js +60 -0
  47. package/lib/webpack/plugins/build-manifest-plugin.d.ts +27 -0
  48. package/lib/webpack/plugins/build-manifest-plugin.js +215 -0
  49. package/lib/webpack/plugins/chunk-names-plugin.d.ts +4 -0
  50. package/lib/webpack/plugins/chunk-names-plugin.js +43 -0
  51. package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
  52. package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
  53. package/lib/webpack/plugins/module-replace-plugin/index.d.ts +1 -0
  54. package/lib/webpack/plugins/module-replace-plugin/index.js +4 -0
  55. package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +31 -0
  56. package/lib/webpack/plugins/module-replace-plugin/plugin.js +177 -0
  57. package/lib/webpack/plugins/module-replace-plugin/stub-loader.d.ts +1 -0
  58. package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +34 -0
  59. package/lib/webpack/plugins/prefer-resolver-plugin.d.ts +10 -0
  60. package/lib/webpack/plugins/prefer-resolver-plugin.js +47 -0
  61. package/lib/webpack/plugins/require-cache-hot-reloader-plugin.d.ts +6 -0
  62. package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +48 -0
  63. package/lib/webpack/types.d.ts +40 -0
  64. package/lib/webpack/types.js +2 -0
  65. package/package.json +80 -0
@@ -0,0 +1,7 @@
1
+ import { Visitor } from '@babel/core';
2
+ export interface IOpts {
3
+ flag?: string;
4
+ }
5
+ export default function (): {
6
+ visitor: Visitor<{}>;
7
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // Based on https://github.com/umijs/umi/blob/83301f25a420daff69ca51a179134c6b1612f5b6/packages/babel-plugin-auto-css-modules/src/index.ts
3
+ // License: https://github.com/umijs/umi/blob/83301f25a420daff69ca51a179134c6b1612f5b6/LICENSE
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const path_1 = require("path");
6
+ const CSS_EXTNAMES = ['.css', '.less', '.sass', '.scss'];
7
+ function default_1() {
8
+ return {
9
+ visitor: {
10
+ ImportDeclaration(path, { opts }) {
11
+ const { specifiers, source, source: { value }, } = path.node;
12
+ if (specifiers.length && CSS_EXTNAMES.includes(path_1.extname(value))) {
13
+ if (value.indexOf('?') >= 0) {
14
+ source.value = `${value}&${opts.flag || 'cssmodules'}`;
15
+ }
16
+ else {
17
+ source.value = `${value}?${opts.flag || 'cssmodules'}`;
18
+ }
19
+ }
20
+ },
21
+ },
22
+ };
23
+ }
24
+ exports.default = default_1;
@@ -0,0 +1,4 @@
1
+ import { PluginObj, types as BabelTypes } from '@babel/core';
2
+ export default function ({ types: t, }: {
3
+ types: typeof BabelTypes;
4
+ }): PluginObj<any>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function default_1({ types: t, }) {
4
+ return {
5
+ inherits: require('babel-plugin-syntax-jsx'),
6
+ visitor: {
7
+ JSXElement(path, state) {
8
+ state.set('jsx', true);
9
+ },
10
+ // Fragment syntax is still JSX since it compiles to createElement(),
11
+ // but JSXFragment is not a JSXElement
12
+ JSXFragment(path, state) {
13
+ state.set('jsx', true);
14
+ },
15
+ Program: {
16
+ exit(path, state) {
17
+ if (state.get('jsx')) {
18
+ const pragma = t.identifier(state.opts.pragma);
19
+ let importAs = pragma;
20
+ // if there's already a React in scope, use that instead of adding an import
21
+ const existingBinding = state.opts.reuseImport !== false &&
22
+ state.opts.importAs &&
23
+ path.scope.getBinding(state.opts.importAs);
24
+ // var _jsx = _pragma.createElement;
25
+ if (state.opts.property) {
26
+ if (state.opts.importAs) {
27
+ importAs = t.identifier(state.opts.importAs);
28
+ }
29
+ else {
30
+ importAs = path.scope.generateUidIdentifier('pragma');
31
+ }
32
+ const mapping = t.variableDeclaration('var', [
33
+ t.variableDeclarator(pragma, t.memberExpression(importAs, t.identifier(state.opts.property))),
34
+ ]);
35
+ // if the React binding came from a require('react'),
36
+ // make sure that our usage comes after it.
37
+ let newPath;
38
+ if (existingBinding &&
39
+ t.isVariableDeclarator(existingBinding.path.node) &&
40
+ t.isCallExpression(existingBinding.path.node.init) &&
41
+ t.isIdentifier(existingBinding.path.node.init.callee) &&
42
+ existingBinding.path.node.init.callee.name === 'require') {
43
+ [newPath] = existingBinding.path.parentPath.insertAfter(
44
+ // @ts-ignore
45
+ mapping);
46
+ }
47
+ else {
48
+ // @ts-ignore
49
+ [newPath] = path.unshiftContainer('body', mapping);
50
+ }
51
+ for (const declar of newPath.get('declarations')) {
52
+ path.scope.registerBinding(newPath.node.kind, declar);
53
+ }
54
+ }
55
+ if (!existingBinding) {
56
+ const importSpecifier = t.importDeclaration([
57
+ state.opts.import
58
+ ? // import { $import as _pragma } from '$module'
59
+ t.importSpecifier(importAs, t.identifier(state.opts.import))
60
+ : state.opts.importNamespace
61
+ ? t.importNamespaceSpecifier(importAs)
62
+ : // import _pragma from '$module'
63
+ t.importDefaultSpecifier(importAs),
64
+ ], t.stringLiteral(state.opts.module || 'react'));
65
+ // @ts-ignore
66
+ const [newPath] = path.unshiftContainer('body', importSpecifier);
67
+ for (const specifier of newPath.get('specifiers')) {
68
+ path.scope.registerBinding('module', specifier);
69
+ }
70
+ }
71
+ }
72
+ },
73
+ },
74
+ },
75
+ };
76
+ }
77
+ exports.default = default_1;
@@ -0,0 +1,24 @@
1
+ /**
2
+ COPYRIGHT (c) 2017-present James Kyle <me@thejameskyle.com>
3
+ MIT License
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
20
+ */
21
+ import { PluginObj, types as BabelTypes } from '@babel/core';
22
+ export default function ({ types: t, }: {
23
+ types: typeof BabelTypes;
24
+ }): PluginObj;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ /**
4
+ COPYRIGHT (c) 2017-present James Kyle <me@thejameskyle.com>
5
+ MIT License
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
22
+ */
23
+ // This file is https://github.com/jamiebuilds/react-loadable/blob/master/src/babel.js
24
+ // Modified to also look for `shuvi/dynamic`
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ function default_1({ types: t, }) {
27
+ return {
28
+ visitor: {
29
+ ImportDeclaration(path) {
30
+ let source = path.node.source.value;
31
+ if (source !== '@shuvi/app')
32
+ return;
33
+ let dynamicSpecifier = path.get('specifiers').find((specifier) => {
34
+ return specifier.node.imported.name === 'dynamic';
35
+ });
36
+ if (!dynamicSpecifier)
37
+ return;
38
+ const bindingName = dynamicSpecifier.node.local.name;
39
+ const binding = path.scope.getBinding(bindingName);
40
+ if (!binding) {
41
+ return;
42
+ }
43
+ binding.referencePaths.forEach((refPath) => {
44
+ const callExpression = refPath.parentPath;
45
+ if (!callExpression.isCallExpression())
46
+ return;
47
+ let args = callExpression.get('arguments');
48
+ if (args.length > 2) {
49
+ throw callExpression.buildCodeFrameError('shuvi/dynamic only accepts 2 arguments');
50
+ }
51
+ if (!args[0]) {
52
+ return;
53
+ }
54
+ let loader;
55
+ let options;
56
+ if (args[0].isObjectExpression()) {
57
+ options = args[0];
58
+ }
59
+ else {
60
+ if (!args[1]) {
61
+ callExpression.node.arguments.push(t.objectExpression([]));
62
+ }
63
+ args = callExpression.get('arguments');
64
+ loader = args[0];
65
+ options = args[1];
66
+ }
67
+ if (!options.isObjectExpression())
68
+ return;
69
+ let properties = options.get('properties');
70
+ let propertiesMap = {};
71
+ properties.forEach((property) => {
72
+ const key = property.get('key');
73
+ propertiesMap[key.node.name] = property;
74
+ });
75
+ if (propertiesMap.webpack) {
76
+ return;
77
+ }
78
+ if (propertiesMap.loader) {
79
+ loader = propertiesMap.loader.get('value');
80
+ }
81
+ if (!loader || Array.isArray(loader)) {
82
+ return;
83
+ }
84
+ const dynamicImports = [];
85
+ loader.traverse({
86
+ Import(path) {
87
+ const args = path.parentPath.get('arguments');
88
+ if (!Array.isArray(args))
89
+ return;
90
+ const node = args[0].node;
91
+ dynamicImports.push(node);
92
+ },
93
+ });
94
+ if (!dynamicImports.length)
95
+ return;
96
+ options.node.properties.push(t.objectProperty(t.identifier('webpack'), t.arrowFunctionExpression([], t.arrayExpression(dynamicImports.map((dynamicImport) => {
97
+ return t.callExpression(t.memberExpression(t.identifier('require'), t.identifier('resolveWeak')), [dynamicImport]);
98
+ })))));
99
+ options.node.properties.push(t.objectProperty(t.identifier('modules'), t.arrayExpression(dynamicImports)));
100
+ });
101
+ },
102
+ },
103
+ };
104
+ }
105
+ exports.default = default_1;
@@ -0,0 +1,4 @@
1
+ import { PluginObj, types as BabelTypes } from '@babel/core';
2
+ export default function ({ types: t, }: {
3
+ types: typeof BabelTypes;
4
+ }): PluginObj<any>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ // Based on https://github.com/zeit/next.js
3
+ // License: https://github.com/zeit/next.js/blob/977bf8d9ebd2845241b8689317f36e4e487f39d0/license.md
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ // matches any hook-like (the default)
6
+ const isHook = /^use[A-Z]/;
7
+ // matches only built-in hooks provided by React et al
8
+ const isBuiltInHook = /^use(Callback|Context|DebugValue|Effect|ImperativeHandle|LayoutEffect|Memo|Reducer|Ref|State)$/;
9
+ function default_1({ types: t, }) {
10
+ const visitor = {
11
+ CallExpression(path, state) {
12
+ const onlyBuiltIns = state.opts.onlyBuiltIns;
13
+ // if specified, options.lib is a list of libraries that provide hook functions
14
+ const libs = state.opts.lib &&
15
+ (state.opts.lib === true
16
+ ? ['react', 'preact/hooks']
17
+ : [].concat(state.opts.lib));
18
+ // skip function calls that are not the init of a variable declaration:
19
+ if (!t.isVariableDeclarator(path.parent))
20
+ return;
21
+ // skip function calls where the return value is not Array-destructured:
22
+ if (!t.isArrayPattern(path.parent.id))
23
+ return;
24
+ // name of the (hook) function being called:
25
+ const hookName = path.node.callee.name;
26
+ if (libs) {
27
+ const binding = path.scope.getBinding(hookName);
28
+ // not an import
29
+ if (!binding || binding.kind !== 'module')
30
+ return;
31
+ const specifier = binding.path.parent
32
+ .source.value;
33
+ // not a match
34
+ if (!libs.some((lib) => lib === specifier))
35
+ return;
36
+ }
37
+ // only match function calls with names that look like a hook
38
+ if (!(onlyBuiltIns ? isBuiltInHook : isHook).test(hookName))
39
+ return;
40
+ // @ts-ignore
41
+ path.parent.id = t.objectPattern(path.parent.id.elements.reduce((patterns, element, i) => {
42
+ if (element === null) {
43
+ return patterns;
44
+ }
45
+ return patterns.concat(t.objectProperty(t.numericLiteral(i), element));
46
+ }, []));
47
+ },
48
+ };
49
+ return {
50
+ name: 'optimize-hook-destructuring',
51
+ visitor: {
52
+ // this is a workaround to run before preset-env destroys destructured assignments
53
+ Program(path, state) {
54
+ path.traverse(visitor, state);
55
+ },
56
+ },
57
+ };
58
+ }
59
+ exports.default = default_1;
@@ -0,0 +1,14 @@
1
+ import { PluginItem } from '@babel/core';
2
+ export declare type PresetOptions = {
3
+ 'preset-env'?: any;
4
+ 'preset-react'?: any;
5
+ 'transform-runtime'?: any;
6
+ };
7
+ declare type BabelPreset = {
8
+ presets?: PluginItem[] | null;
9
+ plugins?: PluginItem[] | null;
10
+ sourceType?: 'script' | 'module' | 'unambiguous';
11
+ overrides?: any[];
12
+ };
13
+ declare const _default: (api: any, options?: PresetOptions) => BabelPreset;
14
+ export default _default;
@@ -0,0 +1,106 @@
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 path_1 = __importDefault(require("path"));
7
+ const env = process.env.NODE_ENV;
8
+ const isProduction = env === 'production';
9
+ const isDevelopment = env === 'development';
10
+ const isTest = env === 'test';
11
+ // Taken from https://github.com/babel/babel/commit/d60c5e1736543a6eac4b549553e107a9ba967051#diff-b4beead8ad9195361b4537601cc22532R158
12
+ function supportsStaticESM(caller) {
13
+ return !!(caller && caller.supportsStaticESM);
14
+ }
15
+ exports.default = (api, options = {}) => {
16
+ const supportsESM = api.caller(supportsStaticESM);
17
+ const isNode = api.caller((caller) => !!caller && caller.isNode);
18
+ const presetEnvConfig = Object.assign({
19
+ // In the test environment `modules` is often needed to be set to true, babel figures that out by itself using the `'auto'` option
20
+ // In production/development this option is set to `false` so that webpack can handle import/export with tree-shaking
21
+ modules: 'auto', exclude: ['transform-typeof-symbol'] }, options['preset-env']);
22
+ // When transpiling for the server or tests, target the current Node version
23
+ // if not explicitly specified:
24
+ if ((isNode || isTest) &&
25
+ (!presetEnvConfig.targets ||
26
+ !(typeof presetEnvConfig.targets === 'object' &&
27
+ 'node' in presetEnvConfig.targets))) {
28
+ presetEnvConfig.targets = {
29
+ // Targets the current process' version of Node. This requires apps be
30
+ // built and deployed on the same version of Node.
31
+ node: 'current'
32
+ };
33
+ }
34
+ return {
35
+ sourceType: 'unambiguous',
36
+ presets: [
37
+ [require('@babel/preset-env').default, presetEnvConfig],
38
+ [
39
+ require('@babel/preset-react'),
40
+ Object.assign({
41
+ // Adds component stack to warning messages
42
+ // Adds __self attribute to JSX which React will use for some warnings
43
+ development: isDevelopment || isTest, pragma: '__jsx',
44
+ // Will use the native built-in instead of trying to polyfill
45
+ // behavior for any plugins that require one.
46
+ useBuiltIns: true }, options['preset-react'])
47
+ ],
48
+ require('@babel/preset-typescript')
49
+ ],
50
+ plugins: [
51
+ require('./plugins/auto-css-modules'),
52
+ [
53
+ require('./plugins/jsx-pragma'),
54
+ {
55
+ // This produces the following injected import for modules containing JSX:
56
+ // import React from 'react';
57
+ // var __jsx = React.createElement;
58
+ module: 'react',
59
+ importAs: 'React',
60
+ pragma: '__jsx',
61
+ property: 'createElement'
62
+ }
63
+ ],
64
+ [
65
+ require('./plugins/optimize-hook-destructuring'),
66
+ {
67
+ // only optimize hook functions imported from React/Preact
68
+ lib: true
69
+ }
70
+ ],
71
+ require('@babel/plugin-syntax-dynamic-import'),
72
+ require('./plugins/loadable-plugin'),
73
+ require('@babel/plugin-proposal-class-properties'),
74
+ [
75
+ require('@babel/plugin-proposal-object-rest-spread'),
76
+ {
77
+ useBuiltIns: true
78
+ }
79
+ ],
80
+ !isNode && [
81
+ require('@babel/plugin-transform-runtime'),
82
+ Object.assign({ version: require('@babel/runtime/package.json').version, false: false, helpers: true, regenerator: true, useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
83
+ // Undocumented option that lets us encapsulate our runtime, ensuring
84
+ // the correct version is used
85
+ // https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
86
+ absoluteRuntime: path_1.default.dirname(require.resolve('@babel/runtime/package.json')) }, options['transform-runtime'])
87
+ ],
88
+ isProduction && [
89
+ require('babel-plugin-transform-react-remove-prop-types'),
90
+ {
91
+ removeImport: true
92
+ }
93
+ ],
94
+ require('@babel/plugin-proposal-optional-chaining'),
95
+ require('@babel/plugin-proposal-nullish-coalescing-operator'),
96
+ isNode && require('@babel/plugin-syntax-bigint'),
97
+ [require('@babel/plugin-proposal-numeric-separator').default, false]
98
+ ].filter(Boolean),
99
+ overrides: [
100
+ {
101
+ test: /\.tsx?$/,
102
+ plugins: [require('@babel/plugin-proposal-numeric-separator').default]
103
+ }
104
+ ]
105
+ };
106
+ };
@@ -0,0 +1 @@
1
+ export declare const AppSourceRegexs: RegExp[];
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppSourceRegexs = [/[/\\]shuvi-app[/\\]/];
@@ -0,0 +1 @@
1
+ export default function (): null;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function default_1() {
4
+ console.warn('You should compile the module before using it.');
5
+ return null;
6
+ }
7
+ exports.default = default_1;
@@ -0,0 +1,4 @@
1
+ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
2
+ export { Issue } from 'fork-ts-checker-webpack-plugin/lib/issue';
3
+ export { createCodeFrameFormatter } from 'fork-ts-checker-webpack-plugin/lib/formatter/CodeFrameFormatter';
4
+ export default ForkTsCheckerWebpackPlugin;
@@ -0,0 +1,9 @@
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 fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
7
+ var CodeFrameFormatter_1 = require("fork-ts-checker-webpack-plugin/lib/formatter/CodeFrameFormatter");
8
+ exports.createCodeFrameFormatter = CodeFrameFormatter_1.createCodeFrameFormatter;
9
+ exports.default = fork_ts_checker_webpack_plugin_1.default;
@@ -0,0 +1,5 @@
1
+ export = formatWebpackMessages;
2
+ declare function formatWebpackMessages(json: any): {
3
+ errors: any;
4
+ warnings: any;
5
+ };
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+ const chalk = require('@shuvi/utils/lib/chalk').default;
9
+ const friendlySyntaxErrorLabel = 'Syntax error:';
10
+ function isLikelyASyntaxError(message) {
11
+ return message.indexOf(friendlySyntaxErrorLabel) !== -1;
12
+ }
13
+ // Cleans up webpack error messages.
14
+ function formatMessage(message, isError) {
15
+ message =
16
+ (message.moduleName ? message.moduleName + '\n' : '') +
17
+ (message.file ? message.file + '\n' : '') +
18
+ message.message;
19
+ let lines = message.split('\n');
20
+ // Strip Webpack-added headers off errors/warnings
21
+ // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
22
+ lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
23
+ // Transform parsing error into syntax error
24
+ // TODO: move this to our ESLint formatter?
25
+ lines = lines.map(line => {
26
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
27
+ if (!parsingError) {
28
+ return line;
29
+ }
30
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
31
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
32
+ });
33
+ message = lines.join('\n');
34
+ // Smoosh syntax errors (commonly found in CSS)
35
+ message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`);
36
+ // Clean up export errors
37
+ message = message.replace(/^.*export '(.+?)' was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$2'.`);
38
+ message = message.replace(/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$2' does not contain a default export (imported as '$1').`);
39
+ message = message.replace(/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`);
40
+ lines = message.split('\n');
41
+ // Remove leading newline
42
+ if (lines.length > 2 && lines[1].trim() === '') {
43
+ lines.splice(1, 1);
44
+ }
45
+ // Clean up file name
46
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
47
+ // Cleans up verbose "module not found" messages for files and packages.
48
+ if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
49
+ lines = [
50
+ lines[0],
51
+ lines[1]
52
+ .replace('Error: ', '')
53
+ .replace('Module not found: Cannot find file:', 'Cannot find file:')
54
+ ];
55
+ }
56
+ // Add helpful message for users trying to use Sass for the first time
57
+ if (lines[1] && lines[1].match(/Cannot find module.+node-sass/)) {
58
+ lines[1] = 'To import Sass files, you first need to install node-sass.\n';
59
+ lines[1] +=
60
+ 'Run `npm install node-sass` or `yarn add node-sass` inside your workspace.';
61
+ }
62
+ lines[0] = chalk.inverse(lines[0]);
63
+ message = lines.join('\n');
64
+ // Internal stacks are generally useless so we strip them... with the
65
+ // exception of stacks containing `webpack:` because they're normally
66
+ // from user code generated by Webpack. For more information see
67
+ // https://github.com/facebook/create-react-app/pull/1050
68
+ message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
69
+ message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
70
+ lines = message.split('\n');
71
+ // Remove duplicated newlines
72
+ lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim());
73
+ // Reassemble the message
74
+ message = lines.join('\n');
75
+ return message.trim();
76
+ }
77
+ function formatWebpackMessages(json) {
78
+ const formattedErrors = json.errors.map(function (message) {
79
+ return formatMessage(message, true);
80
+ });
81
+ const formattedWarnings = json.warnings.map(function (message) {
82
+ return formatMessage(message, false);
83
+ });
84
+ const result = { errors: formattedErrors, warnings: formattedWarnings };
85
+ if (result.errors.some(isLikelyASyntaxError)) {
86
+ // If there are any syntax errors, show just them.
87
+ result.errors = result.errors.filter(isLikelyASyntaxError);
88
+ }
89
+ return result;
90
+ }
91
+ module.exports = formatWebpackMessages;
@@ -0,0 +1 @@
1
+ export function getEventSourceWrapper(options: any): any;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const eventCallbacks = [];
4
+ function EventSourceWrapper(options) {
5
+ var source;
6
+ var lastActivity = new Date();
7
+ var listeners = [];
8
+ if (!options.timeout) {
9
+ options.timeout = 20 * 1000;
10
+ }
11
+ init();
12
+ var timer = setInterval(function () {
13
+ if (new Date() - lastActivity > options.timeout) {
14
+ handleDisconnect();
15
+ }
16
+ }, options.timeout / 2);
17
+ function init() {
18
+ source = new window.EventSource(options.path);
19
+ source.onopen = handleOnline;
20
+ source.onerror = handleDisconnect;
21
+ source.onmessage = handleMessage;
22
+ }
23
+ function handleOnline() {
24
+ if (options.log)
25
+ console.log("[HMR] connected");
26
+ lastActivity = new Date();
27
+ }
28
+ function handleMessage(event) {
29
+ lastActivity = new Date();
30
+ for (var i = 0; i < listeners.length; i++) {
31
+ listeners[i](event);
32
+ }
33
+ if (event.data.indexOf("action") !== -1) {
34
+ eventCallbacks.forEach(cb => cb(event));
35
+ }
36
+ }
37
+ function handleDisconnect() {
38
+ clearInterval(timer);
39
+ source.close();
40
+ setTimeout(init, options.timeout);
41
+ }
42
+ return {
43
+ onclose: () => {
44
+ clearTimeout(timer);
45
+ source.close();
46
+ },
47
+ addMessageListener: function (fn) {
48
+ listeners.push(fn);
49
+ }
50
+ };
51
+ }
52
+ function getEventSourceWrapper(options) {
53
+ if (!window.__whmEventSourceWrapper) {
54
+ window.__whmEventSourceWrapper = {};
55
+ }
56
+ if (!window.__whmEventSourceWrapper[options.path]) {
57
+ // cache the wrapper for other entries loaded on
58
+ // the same page with the same options.path
59
+ window.__whmEventSourceWrapper[options.path] = EventSourceWrapper(options);
60
+ }
61
+ return window.__whmEventSourceWrapper[options.path];
62
+ }
63
+ exports.getEventSourceWrapper = getEventSourceWrapper;
@@ -0,0 +1,4 @@
1
+ export default function connect(options: any): {
2
+ subscribeToHmrEvent(handler: any): void;
3
+ reportRuntimeError(err: any): void;
4
+ };