@modern-js/plugin-docsite 1.0.0 → 1.1.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @modern-js/plugin-docsite
2
2
 
3
+ ## 1.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - fix missing dependencies bug
8
+
9
+ ## 1.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 0fa83663: support more .env files
14
+ - Updated dependencies [6f7fe574]
15
+ - Updated dependencies [e4755134]
16
+ - Updated dependencies [0fa83663]
17
+ - Updated dependencies [19b4f79e]
18
+ - Updated dependencies [f594fbc8]
19
+ - Updated dependencies [d1fde77a]
20
+ - @modern-js/core@1.1.2
21
+ - @modern-js/webpack@1.1.2
22
+ - @modern-js/utils@1.1.2
23
+
24
+ ## 1.1.0
25
+
26
+ ### Minor Changes
27
+
28
+ - 96119db2: Relese v1.1.0### Patch Changes
29
+
30
+ - 6b802b2a: use path method from @modern-js/utils
31
+ - Updated dependencies [96119db2]
32
+ - @modern-js/core@1.1.0
33
+ - @modern-js/webpack@1.1.0
34
+ - @modern-js/utils@1.1.0
35
+
3
36
  ## 1.0.0
4
37
 
5
38
  ### Patch Changes
package/README.md CHANGED
@@ -17,10 +17,7 @@
17
17
 
18
18
  > The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
19
19
 
20
- - 介绍 Modern.js (即将上线)
21
- - [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
22
- - [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
23
- - [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
20
+ - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
24
21
 
25
22
  ## Getting Started
26
23
 
@@ -1,4 +1,4 @@
1
- import { path } from '@modern-js/utils';
1
+ import path from 'path';
2
2
  export const UTILS_STATIC = path.join(__dirname, '../../static');
3
3
  export const DOCS_RENDER_PATH = '/api/v1/docs/render';
4
4
  export const MDX_DEFAULT_RENDERER = `
@@ -1,4 +1,5 @@
1
- import { path, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { logger } from '@modern-js/utils';
2
3
  import webpack from 'webpack';
3
4
  import WebpackDevServer from 'webpack-dev-server';
4
5
  import { chokidarFile } from "./utils/chokidar";
@@ -1,4 +1,5 @@
1
- import { path, fs, Import, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { fs, Import, logger } from '@modern-js/utils';
2
3
  import { valid } from "./utils/valid";
3
4
  const buildFeat = Import.lazy('./build', require);
4
5
  const devFeat = Import.lazy('./dev', require);
@@ -1,4 +1,5 @@
1
- import { path, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { logger } from '@modern-js/utils';
2
3
  import chokidar from 'chokidar';
3
4
  import glob from 'glob';
4
5
  import { generateFiles } from "./generate-files";
@@ -10,7 +10,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
10
10
 
11
11
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
12
 
13
- import { path, logger, fs } from '@modern-js/utils';
13
+ import path from 'path';
14
+ import { logger, fs } from '@modern-js/utils';
14
15
  import matter from 'gray-matter';
15
16
  import GithubSlugger from 'github-slugger';
16
17
  import sortPaths from 'sort-paths';
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import path from 'path';
2
2
  import * as glob from 'glob';
3
3
  import { chalk, fs } from '@modern-js/utils';
4
4
  export const valid = ({
@@ -1,4 +1,5 @@
1
- import { path, fs, upath } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { fs } from '@modern-js/utils';
2
3
  import HtmlWebpackPlugin from 'html-webpack-plugin';
3
4
  import webpack from 'webpack';
4
5
  import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
@@ -23,27 +24,45 @@ export function generatorWebpackConfig(appDirectory, tmpDir, isDev) {
23
24
  templateContent: fs.readFileSync(path.resolve(UTILS_STATIC, 'index.html.ejs'), 'utf8')
24
25
  })]
25
26
  };
26
- config.resolve.modules = [...(config.resolve.modules || []), path.join(__dirname, '../../../../../', 'node_modules')];
27
+ const docsiteNodeModules = [// for yarn
28
+ path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), // for pnpm
29
+ path.resolve(path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), '../..')]; // maybe check if outside appDir or monorepoDir
30
+
31
+ config.resolve.modules = [...(config.resolve.modules || []), ...docsiteNodeModules];
27
32
  config.resolve.alias['@assets'] = path.resolve(appDirectory, 'assets');
28
33
  config.resolve.alias['@styles'] = path.resolve(appDirectory, 'styles'); // fix this since react-live relies on core-js@2
29
34
 
30
- config.resolve.alias[`${path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es';
31
- const pkgJSON = JSON.parse(fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'));
32
-
33
- if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
34
- config.resolve.alias.react = path.resolve('node_modules/react');
35
- } else {
36
- config.resolve.alias.react = path.resolve(__dirname, '../../../../../', 'node_modules', 'react');
37
- }
38
-
39
- if (pkgJSON.dependencies['react-dom'] || pkgJSON.devDependencies['react-dom']) {
40
- config.resolve.alias['react-dom'] = path.resolve('node_modules/react-dom');
41
- } else {
42
- config.resolve.alias['react-dom'] = path.resolve(__dirname, '../../../../../', 'node_modules', 'react-dom');
43
- }
35
+ config.resolve.alias[`${path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es'; // const pkgJSON = JSON.parse(
36
+ // fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
37
+ // );
38
+ // if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
39
+ // (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
40
+ // } else {
41
+ // (config.resolve!.alias as Alias).react = path.resolve(
42
+ // __dirname,
43
+ // '../../../../../',
44
+ // 'node_modules',
45
+ // 'react',
46
+ // );
47
+ // }
48
+ // if (
49
+ // pkgJSON.dependencies['react-dom'] ||
50
+ // pkgJSON.devDependencies['react-dom']
51
+ // ) {
52
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
53
+ // 'node_modules/react-dom',
54
+ // );
55
+ // } else {
56
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
57
+ // __dirname,
58
+ // '../../../../../',
59
+ // 'node_modules',
60
+ // 'react-dom',
61
+ // );
62
+ // }
44
63
 
45
64
  config.resolve.fallback = {
46
- path: upath.normalizeSafe(require.resolve('path-browserify'))
65
+ path: require.resolve('path-browserify')
47
66
  };
48
67
  return config;
49
68
  }
@@ -1,4 +1,4 @@
1
- import { Import, upath } from '@modern-js/utils';
1
+ import { Import } from '@modern-js/utils';
2
2
  const core = Import.lazy('@modern-js/core', require);
3
3
  const features = Import.lazy('./features', require);
4
4
  export default core.createPlugin(() => ({
@@ -39,7 +39,7 @@ export default core.createPlugin(() => ({
39
39
  return {
40
40
  name: 'docsite',
41
41
  title: 'Run Docsite log',
42
- taskPath: upath.normalizeSafe(require.resolve("./build-task")),
42
+ taskPath: require.resolve("./build-task"),
43
43
  params: []
44
44
  };
45
45
  }
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UTILS_STATIC = exports.MDX_DEFAULT_RENDERER = exports.DOCS_RENDER_PATH = void 0;
7
7
 
8
- var _utils = require("@modern-js/utils");
8
+ var _path = _interopRequireDefault(require("path"));
9
9
 
10
- const UTILS_STATIC = _utils.path.join(__dirname, '../../static');
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const UTILS_STATIC = _path.default.join(__dirname, '../../static');
11
13
 
12
14
  exports.UTILS_STATIC = UTILS_STATIC;
13
15
  const DOCS_RENDER_PATH = '/api/v1/docs/render';
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.dev = dev;
7
7
 
8
+ var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _utils = require("@modern-js/utils");
9
11
 
10
12
  var _webpack = _interopRequireDefault(require("webpack"));
@@ -26,7 +28,7 @@ async function dev(appDirectory, tmpDir, files, webpackConfig, isDev, port) {
26
28
  port,
27
29
  historyApiFallback: true,
28
30
  static: {
29
- directory: _utils.path.resolve(appDirectory, 'assets'),
31
+ directory: _path.default.resolve(appDirectory, 'assets'),
30
32
  publicPath: '/assets'
31
33
  }
32
34
  }, compiler);
@@ -5,10 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildDocs = buildDocs;
7
7
 
8
+ var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _utils = require("@modern-js/utils");
9
11
 
10
12
  var _valid = require("./utils/valid");
11
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
12
16
  const buildFeat = _utils.Import.lazy('./build', require);
13
17
 
14
18
  const devFeat = _utils.Import.lazy('./dev', require);
@@ -31,7 +35,7 @@ async function buildDocs({
31
35
  return;
32
36
  }
33
37
 
34
- const docsDir = _utils.path.resolve(appDirectory, 'docs');
38
+ const docsDir = _path.default.resolve(appDirectory, 'docs');
35
39
 
36
40
  if (!_utils.fs.pathExistsSync(docsDir)) {
37
41
  return;
@@ -48,7 +52,7 @@ async function buildDocs({
48
52
  return;
49
53
  }
50
54
 
51
- const tmpDir = _utils.path.join(appDirectory, './node_modules/.modern-js/docs');
55
+ const tmpDir = _path.default.join(appDirectory, './node_modules/.modern-js/docs');
52
56
 
53
57
  _utils.fs.ensureDirSync(tmpDir);
54
58
 
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.chokidarFile = chokidarFile;
7
7
 
8
+ var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _utils = require("@modern-js/utils");
9
11
 
10
12
  var _chokidar = _interopRequireDefault(require("chokidar"));
@@ -32,7 +34,7 @@ function chokidarFile(appDirectory, tmpDir, isDev) {
32
34
  _utils.logger.info('changed, collect and rebuild docs');
33
35
 
34
36
  const files = _glob.default.sync('**/*.{md,mdx}', {
35
- cwd: _utils.path.resolve(appDirectory, 'docs'),
37
+ cwd: _path.default.resolve(appDirectory, 'docs'),
36
38
  ignore: '**/_*'
37
39
  });
38
40
 
@@ -15,6 +15,8 @@ var _camelCase2 = _interopRequireDefault(require("lodash/camelCase"));
15
15
 
16
16
  var _startCase2 = _interopRequireDefault(require("lodash/startCase"));
17
17
 
18
+ var _path = _interopRequireDefault(require("path"));
19
+
18
20
  var _utils = require("@modern-js/utils");
19
21
 
20
22
  var _grayMatter = _interopRequireDefault(require("gray-matter"));
@@ -49,7 +51,7 @@ const loadTemplate = async (file, customPath = false) => {
49
51
  if (customPath) {
50
52
  result = await _utils.fs.readFile(file, 'utf-8');
51
53
  } else {
52
- result = await _utils.fs.readFile(_utils.path.join(_constant.UTILS_STATIC, file), 'utf-8');
54
+ result = await _utils.fs.readFile(_path.default.join(_constant.UTILS_STATIC, file), 'utf-8');
53
55
  }
54
56
 
55
57
  return (0, _template2.default)(result, {
@@ -60,11 +62,11 @@ const loadTemplate = async (file, customPath = false) => {
60
62
  // eslint-disable-next-line max-statements
61
63
  async function handleFile(appDirectory, tmpDir, file, images) {
62
64
  const moduleName = file.replace(/\.(md|mdx)$/, '');
63
- const content = await _utils.fs.readFile(_utils.path.resolve(appDirectory, 'docs', file));
65
+ const content = await _utils.fs.readFile(_path.default.resolve(appDirectory, 'docs', file));
64
66
  const parsed = (0, _grayMatter.default)(content);
65
67
 
66
68
  if (!parsed.data.title) {
67
- parsed.data.title = (0, _startCase2.default)((0, _camelCase2.default)(_utils.path.basename(moduleName)));
69
+ parsed.data.title = (0, _startCase2.default)((0, _camelCase2.default)(_path.default.basename(moduleName)));
68
70
  }
69
71
 
70
72
  const slugger = new _githubSlugger.default();
@@ -146,15 +148,15 @@ async function handleFile(appDirectory, tmpDir, file, images) {
146
148
  } = node;
147
149
 
148
150
  if (!url.startsWith('http')) {
149
- const fullPath = _utils.path.resolve(_utils.path.dirname(_utils.path.resolve(appDirectory, 'docs', file)), url);
151
+ const fullPath = _path.default.resolve(_path.default.dirname(_path.default.resolve(appDirectory, 'docs', file)), url);
150
152
 
151
- const relativePath = _utils.path.relative(_utils.path.resolve(appDirectory, 'assets'), fullPath);
153
+ const relativePath = _path.default.relative(_path.default.resolve(appDirectory, 'assets'), fullPath);
152
154
 
153
155
  if (relativePath.startsWith('..')) {
154
156
  _utils.logger.warn(`${url} referenced in ${file} is not under the "assets" folder`);
155
157
  } else {
156
158
  images.push(relativePath);
157
- node.url = `/${_utils.path.relative(_utils.path.dirname(_utils.path.resolve(appDirectory, 'docs', file)), _utils.path.resolve(appDirectory, 'docs/assets', relativePath))}`;
159
+ node.url = `/${_path.default.relative(_path.default.dirname(_path.default.resolve(appDirectory, 'docs', file)), _path.default.resolve(appDirectory, 'docs/assets', relativePath))}`;
158
160
  }
159
161
  }
160
162
  });
@@ -165,19 +167,19 @@ async function handleFile(appDirectory, tmpDir, file, images) {
165
167
  });
166
168
  const totalExported = (0, _union2.default)(imported.map(n => n.id), exported.map(n => n.id));
167
169
 
168
- const outputFile = _utils.path.resolve(tmpDir, `${moduleName}/mdx.jsx`);
170
+ const outputFile = _path.default.resolve(tmpDir, `${moduleName}/mdx.jsx`);
169
171
 
170
172
  await _utils.fs.outputFile(outputFile, _constant.MDX_DEFAULT_RENDERER + transpiled, {
171
173
  encoding: 'utf8'
172
174
  });
173
175
 
174
- const pageFile = _utils.path.resolve(tmpDir, `${moduleName}/index.jsx`);
176
+ const pageFile = _path.default.resolve(tmpDir, `${moduleName}/index.jsx`);
175
177
 
176
178
  const pageTemplate = await loadTemplate('docs-page.jsx.tpl');
177
179
  const pageContent = pageTemplate({
178
180
  moduleName,
179
181
  toc: JSON.stringify(toc),
180
- relRoot: _utils.path.relative(_utils.path.dirname(outputFile), tmpDir),
182
+ relRoot: _path.default.relative(_path.default.dirname(outputFile), tmpDir),
181
183
  imports: totalExported.length ? `import { ${totalExported.join(', ')} } from './mdx';` : '',
182
184
  imported: totalExported.join(',')
183
185
  });
@@ -197,16 +199,16 @@ async function generateFiles(appDirectory, tmpDir, files, isDev) {
197
199
  const meta = await Promise.all(files.map(file => handleFile(appDirectory, tmpDir, file, images)));
198
200
  const sorted = (0, _sortPaths.default)(meta, e => e.moduleName.endsWith('index') ? e.moduleName.replace(/index$/, '') : `${e.moduleName}/`, '/');
199
201
  const routesTemplate = await loadTemplate('DocsRoutes.jsx.tpl');
200
- await _utils.fs.outputFile(_utils.path.resolve(tmpDir, 'DocsRoutes.jsx'), routesTemplate({
202
+ await _utils.fs.outputFile(_path.default.resolve(tmpDir, 'DocsRoutes.jsx'), routesTemplate({
201
203
  meta: sorted
202
204
  }));
203
- const pkgInfo = await _utils.fs.readJson(_utils.path.resolve(appDirectory, 'package.json'));
205
+ const pkgInfo = await _utils.fs.readJson(_path.default.resolve(appDirectory, 'package.json'));
204
206
  const entryTemplate = await loadTemplate('docs-entry.jsx.tpl');
205
- await _utils.fs.outputFile(_utils.path.resolve(tmpDir, 'docs-entry.jsx'), entryTemplate({
207
+ await _utils.fs.outputFile(_path.default.resolve(tmpDir, 'docs-entry.jsx'), entryTemplate({
206
208
  basename: isDev ? '/' : `${_constant.DOCS_RENDER_PATH}/${pkgInfo.name}/${pkgInfo.version}`
207
209
  }));
208
- await Promise.all(['DocsNav.jsx.tpl', 'DocsToc.jsx.tpl', 'docs.css'].map(async file => _utils.fs.copyFile(_utils.path.resolve(_constant.UTILS_STATIC, file), _utils.path.resolve(tmpDir, file.replace('.tpl', '')))));
209
- await _utils.fs.outputJson(_utils.path.resolve(tmpDir, 'meta.json'), sorted.map(({
210
+ await Promise.all(['DocsNav.jsx.tpl', 'DocsToc.jsx.tpl', 'docs.css'].map(async file => _utils.fs.copyFile(_path.default.resolve(_constant.UTILS_STATIC, file), _path.default.resolve(tmpDir, file.replace('.tpl', '')))));
211
+ await _utils.fs.outputJson(_path.default.resolve(tmpDir, 'meta.json'), sorted.map(({
210
212
  title,
211
213
  moduleName
212
214
  }) => ({
@@ -215,7 +217,7 @@ async function generateFiles(appDirectory, tmpDir, files, isDev) {
215
217
  })), {
216
218
  spaces: 2
217
219
  });
218
- await _utils.fs.ensureDir(_utils.path.resolve(appDirectory, 'dist/docs/assets'));
219
- await Promise.all(Array.from(new Set(images)).map(file => _utils.fs.copyFile(_utils.path.resolve(appDirectory, 'assets', file), _utils.path.resolve(appDirectory, 'dist/docs/assets', file))));
220
+ await _utils.fs.ensureDir(_path.default.resolve(appDirectory, 'dist/docs/assets'));
221
+ await Promise.all(Array.from(new Set(images)).map(file => _utils.fs.copyFile(_path.default.resolve(appDirectory, 'assets', file), _path.default.resolve(appDirectory, 'dist/docs/assets', file))));
220
222
  return sorted;
221
223
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.valid = void 0;
7
7
 
8
- var path = _interopRequireWildcard(require("path"));
8
+ var _path = _interopRequireDefault(require("path"));
9
9
 
10
10
  var glob = _interopRequireWildcard(require("glob"));
11
11
 
@@ -15,11 +15,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
15
15
 
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
 
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
18
20
  const valid = ({
19
21
  appDirectory,
20
22
  docsDir
21
23
  }) => {
22
- const docsAbsPath = path.join(appDirectory, docsDir);
24
+ const docsAbsPath = _path.default.join(appDirectory, docsDir);
25
+
23
26
  const files = glob.sync(`${docsAbsPath}/**/*.{md,mdx}`);
24
27
 
25
28
  if (!_utils.fs.existsSync(docsAbsPath) || files.length <= 0) {
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.generatorWebpackConfig = generatorWebpackConfig;
7
7
  exports.runWebpack = runWebpack;
8
8
 
9
+ var _path = _interopRequireDefault(require("path"));
10
+
9
11
  var _utils = require("@modern-js/utils");
10
12
 
11
13
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
@@ -25,40 +27,58 @@ function generatorWebpackConfig(appDirectory, tmpDir, isDev) {
25
27
  mode: isDev ? 'development' : 'production',
26
28
  context: tmpDir,
27
29
  entry: {
28
- index: _utils.path.resolve(tmpDir, 'docs-entry.jsx')
30
+ index: _path.default.resolve(tmpDir, 'docs-entry.jsx')
29
31
  },
30
32
  output: {
31
- path: _utils.path.resolve(appDirectory, 'dist/docs')
33
+ path: _path.default.resolve(appDirectory, 'dist/docs')
32
34
  },
33
35
  resolve: originConfig.resolve || {
34
36
  alias: {}
35
37
  },
36
38
  module: originConfig.module,
37
39
  plugins: [...plugins, new _htmlWebpackPlugin.default({
38
- templateContent: _utils.fs.readFileSync(_utils.path.resolve(_constant.UTILS_STATIC, 'index.html.ejs'), 'utf8')
40
+ templateContent: _utils.fs.readFileSync(_path.default.resolve(_constant.UTILS_STATIC, 'index.html.ejs'), 'utf8')
39
41
  })]
40
42
  };
41
- config.resolve.modules = [...(config.resolve.modules || []), _utils.path.join(__dirname, '../../../../../', 'node_modules')];
42
- config.resolve.alias['@assets'] = _utils.path.resolve(appDirectory, 'assets');
43
- config.resolve.alias['@styles'] = _utils.path.resolve(appDirectory, 'styles'); // fix this since react-live relies on core-js@2
44
-
45
- config.resolve.alias[`${_utils.path.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es';
46
- const pkgJSON = JSON.parse(_utils.fs.readFileSync(_utils.path.join(appDirectory, 'package.json'), 'utf-8'));
43
+ const docsiteNodeModules = [// for yarn
44
+ _path.default.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), // for pnpm
45
+ _path.default.resolve(_path.default.dirname(require.resolve('@modern-js/plugin-docsite/package.json')), '../..')]; // maybe check if outside appDir or monorepoDir
47
46
 
48
- if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
49
- config.resolve.alias.react = _utils.path.resolve('node_modules/react');
50
- } else {
51
- config.resolve.alias.react = _utils.path.resolve(__dirname, '../../../../../', 'node_modules', 'react');
52
- }
47
+ config.resolve.modules = [...(config.resolve.modules || []), ...docsiteNodeModules];
48
+ config.resolve.alias['@assets'] = _path.default.resolve(appDirectory, 'assets');
49
+ config.resolve.alias['@styles'] = _path.default.resolve(appDirectory, 'styles'); // fix this since react-live relies on core-js@2
53
50
 
54
- if (pkgJSON.dependencies['react-dom'] || pkgJSON.devDependencies['react-dom']) {
55
- config.resolve.alias['react-dom'] = _utils.path.resolve('node_modules/react-dom');
56
- } else {
57
- config.resolve.alias['react-dom'] = _utils.path.resolve(__dirname, '../../../../../', 'node_modules', 'react-dom');
58
- }
51
+ config.resolve.alias[`${_path.default.dirname(require.resolve('core-js'))}/fn`] = 'core-js/es'; // const pkgJSON = JSON.parse(
52
+ // fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
53
+ // );
54
+ // if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
55
+ // (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
56
+ // } else {
57
+ // (config.resolve!.alias as Alias).react = path.resolve(
58
+ // __dirname,
59
+ // '../../../../../',
60
+ // 'node_modules',
61
+ // 'react',
62
+ // );
63
+ // }
64
+ // if (
65
+ // pkgJSON.dependencies['react-dom'] ||
66
+ // pkgJSON.devDependencies['react-dom']
67
+ // ) {
68
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
69
+ // 'node_modules/react-dom',
70
+ // );
71
+ // } else {
72
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
73
+ // __dirname,
74
+ // '../../../../../',
75
+ // 'node_modules',
76
+ // 'react-dom',
77
+ // );
78
+ // }
59
79
 
60
80
  config.resolve.fallback = {
61
- path: _utils.upath.normalizeSafe(require.resolve('path-browserify'))
81
+ path: require.resolve('path-browserify')
62
82
  };
63
83
  return config;
64
84
  }
@@ -49,7 +49,7 @@ var _default = core.createPlugin(() => ({
49
49
  return {
50
50
  name: 'docsite',
51
51
  title: 'Run Docsite log',
52
- taskPath: _utils.upath.normalizeSafe(require.resolve("./build-task")),
52
+ taskPath: require.resolve("./build-task"),
53
53
  params: []
54
54
  };
55
55
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.0.0",
14
+ "version": "1.1.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -25,15 +25,16 @@
25
25
  },
26
26
  "default": "./dist/js/treeshaking/index.js"
27
27
  },
28
- "./cli": "./dist/js/node/index.js"
28
+ "./cli": "./dist/js/node/index.js",
29
+ "./package.json": "./package.json"
29
30
  },
30
31
  "dependencies": {
31
32
  "@babel/parser": "^7.15.2",
32
33
  "@babel/runtime": "^7",
33
34
  "@mdx-js/mdx": "^1.6.22",
34
35
  "@mdx-js/react": "^1.6.22",
35
- "@modern-js/utils": "^1.0.0",
36
- "@modern-js/webpack": "^1.0.0",
36
+ "@modern-js/utils": "^1.1.2",
37
+ "@modern-js/webpack": "^1.1.2",
37
38
  "antd": "^4.16.13",
38
39
  "chokidar": "^3.5.2",
39
40
  "core-js": "^3.17.2",
@@ -57,7 +58,7 @@
57
58
  "webpack-dev-server": "^4.1.1"
58
59
  },
59
60
  "devDependencies": {
60
- "@modern-js/module-tools-hooks": "^1.0.0",
61
+ "@modern-js/module-tools-hooks": "^1.1.1",
61
62
  "@types/core-js": "^2.5.5",
62
63
  "@types/github-slugger": "^1.3.0",
63
64
  "@types/glob": "^7.1.4",
@@ -68,12 +69,12 @@
68
69
  "@types/react-dom": "^17",
69
70
  "@types/webpack-dev-server": "^4.1.0",
70
71
  "typescript": "^4",
71
- "@modern-js/core": "^1.0.0",
72
- "@modern-js/plugin-testing": "^1.0.0",
73
- "@modern-js/module-tools": "^1.0.0"
72
+ "@modern-js/core": "^1.1.2",
73
+ "@modern-js/plugin-testing": "^1.1.1",
74
+ "@modern-js/module-tools": "^1.1.1"
74
75
  },
75
76
  "peerDependencies": {
76
- "@modern-js/core": "^1.0.0"
77
+ "@modern-js/core": "^1.1.2"
77
78
  },
78
79
  "sideEffects": false,
79
80
  "modernConfig": {
@@ -1,4 +1,4 @@
1
- import { path } from '@modern-js/utils';
1
+ import path from 'path';
2
2
 
3
3
  export const UTILS_STATIC = path.join(__dirname, '../../static');
4
4
  export const DOCS_RENDER_PATH = '/api/v1/docs/render';
@@ -1,4 +1,5 @@
1
- import { path, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { logger } from '@modern-js/utils';
2
3
  import webpack, { Configuration } from 'webpack';
3
4
  import WebpackDevServer from 'webpack-dev-server';
4
5
  import { chokidarFile } from './utils/chokidar';
@@ -1,4 +1,5 @@
1
- import { path, fs, Import, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { fs, Import, logger } from '@modern-js/utils';
2
3
  import type { Configuration } from 'webpack';
3
4
  import { valid } from './utils/valid';
4
5
 
@@ -1,4 +1,5 @@
1
- import { path, logger } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { logger } from '@modern-js/utils';
2
3
  import chokidar from 'chokidar';
3
4
  import glob from 'glob';
4
5
  import { generateFiles } from './generate-files';
@@ -1,4 +1,5 @@
1
- import { path, logger, fs } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { logger, fs } from '@modern-js/utils';
2
3
  import matter from 'gray-matter';
3
4
  import { startCase, camelCase, union, template, difference } from 'lodash';
4
5
  import GithubSlugger from 'github-slugger';
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import path from 'path';
2
2
  import * as glob from 'glob';
3
3
  import { chalk, fs } from '@modern-js/utils';
4
4
 
@@ -1,4 +1,5 @@
1
- import { path, fs, upath } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { fs } from '@modern-js/utils';
2
3
  import HtmlWebpackPlugin from 'html-webpack-plugin';
3
4
  import webpack, { Configuration, WebpackPluginInstance } from 'webpack';
4
5
  import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
@@ -34,10 +35,20 @@ export function generatorWebpackConfig(
34
35
  }),
35
36
  ],
36
37
  };
38
+ const docsiteNodeModules = [
39
+ // for yarn
40
+ path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
41
+ // for pnpm
42
+ path.resolve(
43
+ path.dirname(require.resolve('@modern-js/plugin-docsite/package.json')),
44
+ '../..',
45
+ ),
46
+ ];
37
47
 
48
+ // maybe check if outside appDir or monorepoDir
38
49
  config.resolve!.modules = [
39
50
  ...(config.resolve!.modules || []),
40
- path.join(__dirname, '../../../../../', 'node_modules'),
51
+ ...docsiteNodeModules,
41
52
  ];
42
53
  (config.resolve!.alias as Alias)['@assets'] = path.resolve(
43
54
  appDirectory,
@@ -52,37 +63,39 @@ export function generatorWebpackConfig(
52
63
  `${path.dirname(require.resolve('core-js'))}/fn`
53
64
  ] = 'core-js/es';
54
65
 
55
- const pkgJSON = JSON.parse(
56
- fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
57
- );
66
+ // const pkgJSON = JSON.parse(
67
+ // fs.readFileSync(path.join(appDirectory, 'package.json'), 'utf-8'),
68
+ // );
58
69
 
59
- if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
60
- (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
61
- } else {
62
- (config.resolve!.alias as Alias).react = path.resolve(
63
- __dirname,
64
- '../../../../../',
65
- 'node_modules',
66
- 'react',
67
- );
68
- }
69
- if (
70
- pkgJSON.dependencies['react-dom'] ||
71
- pkgJSON.devDependencies['react-dom']
72
- ) {
73
- (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
74
- 'node_modules/react-dom',
75
- );
76
- } else {
77
- (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
78
- __dirname,
79
- '../../../../../',
80
- 'node_modules',
81
- 'react-dom',
82
- );
83
- }
70
+ // if (pkgJSON.dependencies.react || pkgJSON.devDependencies.react) {
71
+ // (config.resolve!.alias as Alias).react = path.resolve('node_modules/react');
72
+ // } else {
73
+ // (config.resolve!.alias as Alias).react = path.resolve(
74
+ // __dirname,
75
+ // '../../../../../',
76
+ // 'node_modules',
77
+ // 'react',
78
+ // );
79
+ // }
80
+ // if (
81
+ // pkgJSON.dependencies['react-dom'] ||
82
+ // pkgJSON.devDependencies['react-dom']
83
+ // ) {
84
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
85
+ // 'node_modules/react-dom',
86
+ // );
87
+ // } else {
88
+ // (config.resolve!.alias as Alias)['react-dom'] = path.resolve(
89
+ // __dirname,
90
+ // '../../../../../',
91
+ // 'node_modules',
92
+ // 'react-dom',
93
+ // );
94
+ // }
84
95
 
85
- config.resolve!.fallback = { path: upath.normalizeSafe(require.resolve('path-browserify')) };
96
+ config.resolve!.fallback = {
97
+ path: require.resolve('path-browserify'),
98
+ };
86
99
  return config;
87
100
  }
88
101
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Import, upath } from '@modern-js/utils';
1
+ import { Import } from '@modern-js/utils';
2
2
 
3
3
  const core: typeof import('@modern-js/core') = Import.lazy(
4
4
  '@modern-js/core',
@@ -33,7 +33,7 @@ export default core.createPlugin(
33
33
  return {
34
34
  name: 'docsite',
35
35
  title: 'Run Docsite log',
36
- taskPath: upath.normalizeSafe(require.resolve('./build-task')),
36
+ taskPath: require.resolve('./build-task'),
37
37
  params: [],
38
38
  };
39
39
  },