@umijs/core 4.0.0-beta.16 → 4.0.0-beta.17

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.
@@ -1,4 +1,5 @@
1
1
  export declare function getConventionRoutes(opts: {
2
2
  base: string;
3
3
  prefix?: string;
4
+ exclude?: RegExp[];
4
5
  }): any;
@@ -18,12 +18,9 @@ function getConventionRoutes(opts) {
18
18
  dir: opts.base,
19
19
  visitor: (file) => {
20
20
  const routeId = (0, utils_2.createRouteId)(file);
21
- if ((0, utils_2.isRouteModuleFile)({ file })) {
21
+ if ((0, utils_2.isRouteModuleFile)({ file: (0, utils_1.winPath)(file), exclude: opts.exclude })) {
22
22
  files[routeId] = (0, utils_1.winPath)(file);
23
23
  }
24
- else {
25
- throw new Error(`Invalid route module file: ${(0, path_1.join)(opts.base, file)}`);
26
- }
27
24
  },
28
25
  });
29
26
  const routeIds = Object.keys(files).sort(utils_2.byLongestFirst);
@@ -52,13 +49,13 @@ function visitFiles(opts) {
52
49
  visitFiles(Object.assign(Object.assign({}, opts), { dir: file }));
53
50
  }
54
51
  else if (stat.isFile() &&
55
- ['.tsx', '.ts', '.js', '.jsx'].includes((0, path_1.extname)(file))) {
52
+ ['.tsx', '.ts', '.js', '.jsx', '.md', '.mdx'].includes((0, path_1.extname)(file))) {
56
53
  opts.visitor((0, path_1.relative)(opts.baseDir, file));
57
54
  }
58
55
  }
59
56
  }
60
57
  function createRoutePath(routeId) {
61
- const path = routeId
58
+ let path = routeId
62
59
  // routes/$ -> routes/*
63
60
  // routes/nested/$.tsx (with a "routes/nested.tsx" layout)
64
61
  .replace(/^\$$/, '*')
@@ -69,5 +66,7 @@ function createRoutePath(routeId) {
69
66
  .replace(/\$/g, ':')
70
67
  // routes/not.nested -> routes/not/nested
71
68
  .replace(/\./g, '/');
72
- return /\b\/?index$/.test(path) ? path.replace(/\/?index$/, '') : path;
69
+ path = /\b\/?index$/.test(path) ? path.replace(/\/?index$/, '') : path;
70
+ path = /\b\/?README$/.test(path) ? path.replace(/\/?README$/, '') : path;
71
+ return path;
73
72
  }
@@ -4,4 +4,5 @@ export declare function byLongestFirst(a: string, b: string): number;
4
4
  export declare function findParentRouteId(routeIds: string[], childRouteId: string): string | undefined;
5
5
  export declare function isRouteModuleFile(opts: {
6
6
  file: string;
7
+ exclude?: RegExp[];
7
8
  }): boolean;
@@ -21,6 +21,14 @@ function findParentRouteId(routeIds, childRouteId) {
21
21
  exports.findParentRouteId = findParentRouteId;
22
22
  const routeModuleExts = ['.js', '.jsx', '.ts', '.tsx', '.md', '.mdx'];
23
23
  function isRouteModuleFile(opts) {
24
+ // TODO: add cache strategy
25
+ for (const excludeRegExp of opts.exclude || []) {
26
+ if (opts.file &&
27
+ excludeRegExp instanceof RegExp &&
28
+ excludeRegExp.test(opts.file)) {
29
+ return false;
30
+ }
31
+ }
24
32
  return routeModuleExts.includes((0, path_1.extname)(opts.file));
25
33
  }
26
34
  exports.isRouteModuleFile = isRouteModuleFile;
@@ -114,9 +114,9 @@ class Plugin {
114
114
  .split(',')
115
115
  .filter(Boolean),
116
116
  // dependencies
117
- ...Object.keys(opts.pkg.devDependencies || {})
118
- .concat(Object.keys(opts.pkg.dependencies || {}))
119
- .filter(Plugin.isPluginOrPreset.bind(null, type)),
117
+ // ...Object.keys(opts.pkg.devDependencies || {})
118
+ // .concat(Object.keys(opts.pkg.dependencies || {}))
119
+ // .filter(Plugin.isPluginOrPreset.bind(null, type)),
120
120
  // user config
121
121
  ...(opts.userConfig[types] || []),
122
122
  ].map((path) => {
@@ -52,7 +52,13 @@ export declare class Service {
52
52
  stage: ServiceStage;
53
53
  userConfig: Record<string, any>;
54
54
  configManager: Config | null;
55
- pkg: Record<string, string | Record<string, any>>;
55
+ pkg: {
56
+ name?: string;
57
+ version?: string;
58
+ dependencies?: Record<string, string>;
59
+ devDependencies?: Record<string, string>;
60
+ [key: string]: any;
61
+ };
56
62
  pkgPath: string;
57
63
  constructor(opts: IOpts);
58
64
  applyPlugins<T>(opts: {
@@ -313,6 +313,7 @@ class Service {
313
313
  'config',
314
314
  'cwd',
315
315
  'pkg',
316
+ 'pkgPath',
316
317
  'name',
317
318
  'paths',
318
319
  'userConfig',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.0.0-beta.16",
3
+ "version": "4.0.0-beta.17",
4
4
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
5
5
  "bugs": "https://github.com/umijs/umi-next/issues",
6
6
  "repository": {
@@ -20,8 +20,8 @@
20
20
  "dev": "pnpm build -- --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@umijs/bundler-utils": "4.0.0-beta.16",
24
- "@umijs/utils": "4.0.0-beta.16"
23
+ "@umijs/bundler-utils": "4.0.0-beta.17",
24
+ "@umijs/utils": "4.0.0-beta.17"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@hapi/joi": "17.1.1",