Yuki Takei 3 лет назад
Родитель
Сommit
5aeb23f750

+ 1 - 0
package.json

@@ -71,6 +71,7 @@
     "eslint-plugin-jest": "^26.5.3",
     "eslint-plugin-react": "^7.30.1",
     "eslint-plugin-react-hooks": "^4.6.0",
+    "glob": "^8.1.0",
     "jest": "^28.1.3",
     "jest-date-mock": "^1.0.8",
     "jest-localstorage-mock": "^2.4.14",

+ 2 - 2
packages/core/package.json

@@ -6,8 +6,8 @@
   "keywords": [
     "growi"
   ],
-  "main": "dist/core.umd.js",
-  "module": "dist/core.mjs",
+  "main": "dist/index.js",
+  "module": "dist/index.mjs",
   "types": "types/index.d.ts",
   "files": [
     "dist",

+ 17 - 0
packages/core/src/utils/page-path-utils/collect-ancestor-paths.ts

@@ -0,0 +1,17 @@
+import platformPath from 'node:path';
+
+import { isTopPage } from './is-top-page';
+
+/**
+ * returns ancestors paths
+ * @param {string} path
+ * @param {string[]} ancestorPaths
+ * @returns {string[]}
+ */
+export const collectAncestorPaths = (path: string, ancestorPaths: string[] = []): string[] => {
+  if (isTopPage(path)) return ancestorPaths;
+
+  const parentPath = platformPath.dirname(path);
+  ancestorPaths.push(parentPath);
+  return collectAncestorPaths(parentPath, ancestorPaths);
+};

+ 5 - 25
packages/core/src/utils/page-path-utils.ts → packages/core/src/utils/page-path-utils/index.ts

@@ -1,17 +1,11 @@
-import nodePath from 'path';
-
 import escapeStringRegexp from 'escape-string-regexp';
 
-import { isValidObjectId } from './objectid-utils';
-import { addTrailingSlash } from './path-utils';
+import { isValidObjectId } from '../objectid-utils';
+import { addTrailingSlash } from '../path-utils';
 
-/**
- * Whether path is the top page
- * @param path
- */
-export const isTopPage = (path: string): boolean => {
-  return path === '/';
-};
+import { isTopPage as _isTopPage } from './is-top-page';
+
+export const isTopPage = _isTopPage;
 
 /**
  * Whether path is the top page of users
@@ -187,20 +181,6 @@ export const generateEditorPath = (...paths: string[]): string => {
   }
 };
 
-/**
- * returns ancestors paths
- * @param {string} path
- * @param {string[]} ancestorPaths
- * @returns {string[]}
- */
-export const collectAncestorPaths = (path: string, ancestorPaths: string[] = []): string[] => {
-  if (isTopPage(path)) return ancestorPaths;
-
-  const parentPath = nodePath.dirname(path);
-  ancestorPaths.push(parentPath);
-  return collectAncestorPaths(parentPath, ancestorPaths);
-};
-
 /**
  * return paths without duplicate area of regexp /^${path}\/.+/i
  * ex. expect(omitDuplicateAreaPathFromPaths(['/A', '/A/B', '/A/B/C'])).toStrictEqual(['/A'])

+ 7 - 0
packages/core/src/utils/page-path-utils/is-top-page.ts

@@ -0,0 +1,7 @@
+/**
+ * Whether path is the top page
+ * @param path
+ */
+export const isTopPage = (path: string): boolean => {
+  return path === '/';
+};

+ 1 - 1
packages/core/src/utils/page-utils.ts

@@ -1,4 +1,4 @@
-import { isTopPage } from './page-path-utils';
+import { isTopPage } from './page-path-utils/is-top-page';
 
 // const GRANT_PUBLIC = 1;
 const GRANT_RESTRICTED = 2;

+ 10 - 2
packages/core/vite.config.ts

@@ -1,3 +1,6 @@
+import path from 'path';
+
+import glob from 'glob';
 import { defineConfig } from 'vite';
 import dts from 'vite-plugin-dts';
 
@@ -9,14 +12,19 @@ export default defineConfig({
   build: {
     outDir: 'dist',
     lib: {
-      entry: 'src/index.ts',
+      entry: glob.sync(path.resolve(__dirname, 'src/**/*.ts')),
       name: 'core-libs',
-      formats: ['es', 'umd'],
+      formats: ['es', 'cjs'],
     },
     rollupOptions: {
+      output: {
+        preserveModules: true,
+        preserveModulesRoot: 'src',
+      },
       external: [
         'bson-objectid',
         'swr',
+        /^node:.*/,
       ],
     },
   },

+ 11 - 0
yarn.lock

@@ -10047,6 +10047,17 @@ glob@^8.0.0:
     minimatch "^5.0.1"
     once "^1.3.0"
 
+glob@^8.1.0:
+  version "8.1.0"
+  resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
+  integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==
+  dependencies:
+    fs.realpath "^1.0.0"
+    inflight "^1.0.4"
+    inherits "2"
+    minimatch "^5.0.1"
+    once "^1.3.0"
+
 global-dirs@^3.0.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.0.tgz#70a76fe84ea315ab37b1f5576cbde7d48ef72686"