@shuvi/toolpack 0.0.1-rc.34 → 0.0.1-rc.37

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,2 @@
1
+ import { Runtime } from '@shuvi/types';
2
+ export declare function createLaunchEditorMiddleware(launchEditorEndpoint: string): Runtime.IServerMiddlewareHandler;
@@ -0,0 +1,50 @@
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 launch_editor_1 = __importDefault(require("launch-editor"));
16
+ function getSourcePath(source) {
17
+ // Webpack prefixes certain source paths with this path
18
+ if (source.startsWith('webpack:///')) {
19
+ return source.substring(11);
20
+ }
21
+ // Make sure library name is filtered out as well
22
+ if (source.startsWith('webpack://_N_E/')) {
23
+ return source.substring(15);
24
+ }
25
+ if (source.startsWith('webpack://')) {
26
+ return source.substring(10);
27
+ }
28
+ if (source.startsWith('/')) {
29
+ return source.substring(1);
30
+ }
31
+ return source;
32
+ }
33
+ function createLaunchEditorMiddleware(launchEditorEndpoint) {
34
+ return function launchEditorMiddleware(ctx, next) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ if (ctx.request.url.startsWith(launchEditorEndpoint)) {
37
+ const { query } = ctx.req.parsedUrl;
38
+ const lineNumber = parseInt(query.lineNumber, 10) || 1;
39
+ const colNumber = parseInt(query.colNumber, 10) || 1;
40
+ launch_editor_1.default(getSourcePath(`${query.fileName}:${lineNumber}:${colNumber}`));
41
+ ctx.body = '';
42
+ return;
43
+ }
44
+ else {
45
+ yield next();
46
+ }
47
+ });
48
+ };
49
+ }
50
+ exports.createLaunchEditorMiddleware = createLaunchEditorMiddleware;
@@ -187,7 +187,8 @@ function baseWebpackChain({ dev, projectRoot, srcDirs, mediaFilename, name, buil
187
187
  const stringifiedEnvs = Object.entries(Object.assign(Object.assign({}, shuviConfigEnv), shuviPublicEnv)).reduce((prev, [key, value]) => {
188
188
  return `${prev}|${key}=${value}`;
189
189
  }, '');
190
- const SHUVI_VERSION = require('shuvi/package.json').version;
190
+ const PACKAGE_JSON = path_1.default.resolve(__dirname, '../../../package.json');
191
+ const SHUVI_VERSION = require(PACKAGE_JSON).version;
191
192
  return {
192
193
  cacheDirectory: path_1.default.resolve(`node_modules/.cache/webpack/${projectHash}`),
193
194
  type: 'filesystem',
@@ -195,9 +196,7 @@ function baseWebpackChain({ dev, projectRoot, srcDirs, mediaFilename, name, buil
195
196
  version: `${SHUVI_VERSION}|${stringifiedEnvs}`
196
197
  };
197
198
  };
198
- config.cache(typeof process.env.SHUVI_DEV_DISABLE_CACHE !== 'undefined'
199
- ? false
200
- : getCacheConfig());
199
+ config.cache(getCacheConfig());
201
200
  if (dev) {
202
201
  // For webpack-dev-middleware usage
203
202
  config.watchOptions({
@@ -1,6 +1,6 @@
1
1
  import WebpackChain from 'webpack-chain';
2
2
  import { BaseOptions } from './base';
3
- import { IWebpackHelpers } from '../types';
3
+ import { IWebpackHelpers } from '@shuvi/types/src/bundler';
4
4
  export interface BrowserOptions extends BaseOptions {
5
5
  webpackHelpers: IWebpackHelpers;
6
6
  analyze?: boolean;
@@ -18,7 +18,7 @@ const crypto_1 = __importDefault(require("crypto"));
18
18
  const webpack_1 = __importDefault(require("webpack"));
19
19
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
20
20
  const detectTypescript_1 = require("@shuvi/utils/lib/detectTypescript");
21
- // import PreferResolverPlugin from '../plugins/prefer-resolver-plugin';
21
+ const prefer_resolver_plugin_1 = __importDefault(require("../plugins/prefer-resolver-plugin"));
22
22
  const base_1 = require("./base");
23
23
  const style_1 = require("./parts/style");
24
24
  const BIG_LIBRARY_THRESHOLD = 160000; // byte
@@ -37,11 +37,11 @@ function createBrowserWebpackChain(_a) {
37
37
  '.json',
38
38
  '.wasm'
39
39
  ]);
40
- // if (baseOptions.target) {
41
- // chain.resolve
42
- // .plugin('private/prefer-resolver-plugin')
43
- // .use(PreferResolverPlugin, [{ suffix: baseOptions.target }]);
44
- // }
40
+ if (baseOptions.target) {
41
+ chain.resolve
42
+ .plugin('private/prefer-resolver-plugin')
43
+ .use(prefer_resolver_plugin_1.default, [{ suffix: baseOptions.target }]);
44
+ }
45
45
  if (dev) {
46
46
  chain.plugin('private/hmr-plugin').use(webpack_1.default.HotModuleReplacementPlugin);
47
47
  }
@@ -1,6 +1,6 @@
1
1
  import WebpackChain from 'webpack-chain';
2
2
  import { BaseOptions } from './base';
3
- import { IWebpackHelpers } from '../types';
3
+ import { IWebpackHelpers } from '@shuvi/types/src/bundler';
4
4
  export interface NodeOptions extends BaseOptions {
5
5
  webpackHelpers: IWebpackHelpers;
6
6
  }
@@ -1,4 +1,4 @@
1
- import { ExternalsFunction } from '../../types';
1
+ import { ExternalsFunction } from '@shuvi/types/src/bundler';
2
2
  export declare function nodeExternals({ projectRoot }: {
3
3
  projectRoot: string;
4
4
  }): ExternalsFunction;
@@ -30,9 +30,7 @@ function nodeExternals({ projectRoot }) {
30
30
  return next(null, `commonjs ${request}`);
31
31
  }
32
32
  const notExternalModules = [];
33
- const externalModules = [
34
- /@shuvi[/\\]service[/\\]lib[/\\]lib[/\\]runtimeConfig/
35
- ];
33
+ const externalModules = [/shuvi[/\\]lib[/\\]lib[/\\]runtimeConfig/];
36
34
  // make sure we don't externalize anything that is
37
35
  // supposed to be transpiled
38
36
  if (match(request, constants_1.AppSourceRegexs)) {
@@ -1,3 +1,2 @@
1
- import { IWebpackHelpers } from '../../types';
1
+ import { IWebpackHelpers } from '@shuvi/types/src/bundler';
2
2
  export declare const webpackHelpers: () => IWebpackHelpers;
3
- export declare function shouldUseRelativeAssetPaths(publicPath: string): boolean;
@@ -42,7 +42,3 @@ exports.webpackHelpers = () => {
42
42
  }
43
43
  };
44
44
  };
45
- function shouldUseRelativeAssetPaths(publicPath) {
46
- return publicPath === './';
47
- }
48
- exports.shouldUseRelativeAssetPaths = shouldUseRelativeAssetPaths;
@@ -8,7 +8,9 @@ const Rule_1 = __importDefault(require("webpack-chain/src/Rule"));
8
8
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
9
  const loader_utils_1 = __importDefault(require("loader-utils"));
10
10
  const path_1 = __importDefault(require("path"));
11
- const helpers_1 = require("./helpers");
11
+ function shouldUseRelativeAssetPaths(publicPath) {
12
+ return publicPath === './';
13
+ }
12
14
  function getCSSModuleLocalIdent(context, localIdentName, localName, options) {
13
15
  // Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
14
16
  const fileNameOrFolder = context.resourcePath.match(/index\.module\.(css|scss|sass)$/)
@@ -67,7 +69,7 @@ function cssRule({ publicPath, test, resourceQuery, cssModule, extractCss, sourc
67
69
  rule
68
70
  .use('extract-loader')
69
71
  .loader(mini_css_extract_plugin_1.default.loader)
70
- .options(Object.assign({}, (publicPath && helpers_1.shouldUseRelativeAssetPaths(publicPath)
72
+ .options(Object.assign({}, (publicPath && shouldUseRelativeAssetPaths(publicPath)
71
73
  ? {
72
74
  // path relative to outdir from the generated css file
73
75
  publicPath: '../../'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/toolpack",
3
- "version": "0.0.1-rc.34",
3
+ "version": "0.0.1-rc.37",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -11,11 +11,6 @@
11
11
  "files": [
12
12
  "lib"
13
13
  ],
14
- "scripts": {
15
- "dev": "tsc -p tsconfig.build.json -w",
16
- "prebuild": "rimraf lib",
17
- "build": "tsc -p tsconfig.build.json"
18
- },
19
14
  "engines": {
20
15
  "node": ">= 12.0.0"
21
16
  },
@@ -33,8 +28,9 @@
33
28
  "@babel/preset-react": "7.10.1",
34
29
  "@babel/preset-typescript": "7.12.7",
35
30
  "@babel/runtime": "7.12.5",
36
- "@shuvi/shared": "0.0.1-rc.34",
37
- "@shuvi/utils": "0.0.1-rc.34",
31
+ "@shuvi/shared": "0.0.1-rc.36",
32
+ "@shuvi/types": "0.0.1-rc.37",
33
+ "@shuvi/utils": "0.0.1-rc.36",
38
34
  "babel-loader": "8.2.2",
39
35
  "babel-plugin-syntax-jsx": "6.18.0",
40
36
  "babel-plugin-transform-define": "2.0.0",
@@ -45,6 +41,7 @@
45
41
  "file-loader": "6.2.0",
46
42
  "fork-ts-checker-webpack-plugin": "6.0.8",
47
43
  "ignore-loader": "0.1.2",
44
+ "launch-editor": "2.2.1",
48
45
  "loader-utils": "2.0.0",
49
46
  "mini-css-extract-plugin": "1.3.9",
50
47
  "path-browserify": "1.0.1",
@@ -69,6 +66,7 @@
69
66
  "@types/loader-utils": "2.0.1",
70
67
  "@types/mini-css-extract-plugin": "^1.2.2",
71
68
  "@types/terser-webpack-plugin": "5.0.2",
69
+ "@types/webpack": "4.41.0",
72
70
  "@types/webpack-bundle-analyzer": "^3.8.0",
73
71
  "memfs": "^3.1.2",
74
72
  "webpack": "5.36.0"
@@ -76,5 +74,9 @@
76
74
  "peerDependencies": {
77
75
  "webpack": "5.36.0"
78
76
  },
79
- "gitHead": "10ebaa2a20fd06bc7f34be0feeddef9a26f9dddd"
80
- }
77
+ "scripts": {
78
+ "dev": "tsc -p tsconfig.build.json -w",
79
+ "prebuild": "rimraf lib",
80
+ "build": "tsc -p tsconfig.build.json"
81
+ }
82
+ }
@@ -1,40 +0,0 @@
1
- import WebpackChain from 'webpack-chain';
2
- export interface IModuleItem {
3
- id: string;
4
- name: string;
5
- }
6
- export interface IModule {
7
- files: string[];
8
- children: IModuleItem[];
9
- }
10
- export declare type IAssetMap = {
11
- js: string[];
12
- css?: string[];
13
- } & {
14
- [ext: string]: string[];
15
- };
16
- export interface IChunk {
17
- file: string;
18
- request: string;
19
- }
20
- export interface IManifest {
21
- entries: {
22
- [s: string]: IAssetMap;
23
- };
24
- bundles: {
25
- [name: string]: string;
26
- };
27
- chunkRequest: {
28
- [file: string]: string;
29
- };
30
- loadble: {
31
- [s: string]: IModule;
32
- };
33
- }
34
- export declare type ExternalsFunction = (data: {
35
- context: string;
36
- request: string;
37
- }, callback: (err: Error | null, result: string | undefined) => void) => void;
38
- export interface IWebpackHelpers {
39
- addExternals: (chain: WebpackChain, externalsFn: ExternalsFunction) => void;
40
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });