@modern-js/plugin-server-build 1.2.0 → 1.2.3

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,44 @@
1
1
  # @modern-js/plugin-server-build
2
2
 
3
+ ## 1.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 61e3f623: feat: convert to new plugin
8
+ - 681a1ff9: feat: remove unnecessary peerDependencies
9
+ - Updated dependencies [c2046f37]
10
+ - @modern-js/utils@1.3.6
11
+
12
+ ## 1.2.2
13
+
14
+ ### Patch Changes
15
+
16
+ - 55e18278: chore: remove unused dependencies and devDependencies
17
+ - Updated dependencies [969f172f]
18
+ - Updated dependencies [4c792f68]
19
+ - Updated dependencies [4b5d4bf4]
20
+ - Updated dependencies [62f5b8c8]
21
+ - Updated dependencies [55e18278]
22
+ - Updated dependencies [4499a674]
23
+ - Updated dependencies [403f5169]
24
+ - Updated dependencies [a7f42f48]
25
+ - @modern-js/core@1.4.4
26
+ - @modern-js/utils@1.3.3
27
+ - @modern-js/babel-compiler@1.2.2
28
+
29
+ ## 1.2.1
30
+
31
+ ### Patch Changes
32
+
33
+ - 83166714: change .npmignore
34
+ - Updated dependencies [83166714]
35
+ - Updated dependencies [c3de9882]
36
+ - Updated dependencies [33ff48af]
37
+ - @modern-js/core@1.3.2
38
+ - @modern-js/server-utils@1.2.1
39
+ - @modern-js/babel-compiler@1.2.1
40
+ - @modern-js/utils@1.2.2
41
+
3
42
  ## 1.2.0
4
43
 
5
44
  ### Minor Changes
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
4
3
  import { compiler } from '@modern-js/babel-compiler';
5
4
  import { resolveBabelConfig } from '@modern-js/server-utils';
6
5
  const SERVER_DIR = './server';
@@ -37,48 +36,43 @@ const compile = async (appDirectory, modernConfig, compileOptions) => {
37
36
  });
38
37
  };
39
38
 
40
- export default createPlugin(() => ({
41
- config() {
42
- return {};
43
- },
39
+ export default (() => ({
40
+ name: '@modern-js/plugin-server-build',
41
+ setup: api => ({
42
+ async afterBuild() {
43
+ const {
44
+ appDirectory,
45
+ distDirectory
46
+ } = api.useAppContext();
47
+ const modernConfig = api.useResolvedConfigContext();
48
+ const distDir = path.resolve(distDirectory);
49
+ const serverDir = path.resolve(appDirectory, SERVER_DIR);
50
+ const sharedDir = path.resolve(appDirectory, SHARED_DIR);
51
+ const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
52
+ const patterns = [];
44
53
 
45
- async afterBuild() {
46
- // eslint-disable-next-line react-hooks/rules-of-hooks
47
- const {
48
- appDirectory,
49
- distDirectory
50
- } = useAppContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
51
-
52
- const modernConfig = useResolvedConfigContext();
53
- const distDir = path.resolve(distDirectory);
54
- const serverDir = path.resolve(appDirectory, SERVER_DIR);
55
- const sharedDir = path.resolve(appDirectory, SHARED_DIR);
56
- const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
57
- const patterns = [];
54
+ if (fs.existsSync(serverDir)) {
55
+ patterns.push({
56
+ from: serverDir,
57
+ to: distDir,
58
+ tsconfigPath
59
+ });
60
+ }
58
61
 
59
- if (fs.existsSync(serverDir)) {
60
- patterns.push({
61
- from: serverDir,
62
- to: distDir,
63
- tsconfigPath
64
- });
65
- }
66
-
67
- if (fs.existsSync(sharedDir)) {
68
- patterns.push({
69
- from: sharedDir,
70
- to: distDir,
71
- tsconfigPath
72
- });
73
- }
62
+ if (fs.existsSync(sharedDir)) {
63
+ patterns.push({
64
+ from: sharedDir,
65
+ to: distDir,
66
+ tsconfigPath
67
+ });
68
+ }
74
69
 
75
- if (patterns.length > 0) {
76
- await compile(appDirectory, modernConfig, {
77
- patterns
78
- });
70
+ if (patterns.length > 0) {
71
+ await compile(appDirectory, modernConfig, {
72
+ patterns
73
+ });
74
+ }
79
75
  }
80
- }
81
76
 
82
- }), {
83
- name: '@modern-js/plugin-server-build'
84
- });
77
+ })
78
+ }));
@@ -9,8 +9,6 @@ var _fs = _interopRequireDefault(require("fs"));
9
9
 
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
 
12
- var _core = require("@modern-js/core");
13
-
14
12
  var _babelCompiler = require("@modern-js/babel-compiler");
15
13
 
16
14
  var _serverUtils = require("@modern-js/server-utils");
@@ -51,55 +49,50 @@ const compile = async (appDirectory, modernConfig, compileOptions) => {
51
49
  });
52
50
  };
53
51
 
54
- var _default = (0, _core.createPlugin)(() => ({
55
- config() {
56
- return {};
57
- },
58
-
59
- async afterBuild() {
60
- // eslint-disable-next-line react-hooks/rules-of-hooks
61
- const {
62
- appDirectory,
63
- distDirectory
64
- } = (0, _core.useAppContext)(); // eslint-disable-next-line react-hooks/rules-of-hooks
65
-
66
- const modernConfig = (0, _core.useResolvedConfigContext)();
67
-
68
- const distDir = _path.default.resolve(distDirectory);
69
-
70
- const serverDir = _path.default.resolve(appDirectory, SERVER_DIR);
71
-
72
- const sharedDir = _path.default.resolve(appDirectory, SHARED_DIR);
73
-
74
- const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
75
-
76
- const patterns = [];
77
-
78
- if (_fs.default.existsSync(serverDir)) {
79
- patterns.push({
80
- from: serverDir,
81
- to: distDir,
82
- tsconfigPath
83
- });
84
- }
85
-
86
- if (_fs.default.existsSync(sharedDir)) {
87
- patterns.push({
88
- from: sharedDir,
89
- to: distDir,
90
- tsconfigPath
91
- });
92
- }
93
-
94
- if (patterns.length > 0) {
95
- await compile(appDirectory, modernConfig, {
96
- patterns
97
- });
52
+ var _default = () => ({
53
+ name: '@modern-js/plugin-server-build',
54
+ setup: api => ({
55
+ async afterBuild() {
56
+ const {
57
+ appDirectory,
58
+ distDirectory
59
+ } = api.useAppContext();
60
+ const modernConfig = api.useResolvedConfigContext();
61
+
62
+ const distDir = _path.default.resolve(distDirectory);
63
+
64
+ const serverDir = _path.default.resolve(appDirectory, SERVER_DIR);
65
+
66
+ const sharedDir = _path.default.resolve(appDirectory, SHARED_DIR);
67
+
68
+ const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
69
+
70
+ const patterns = [];
71
+
72
+ if (_fs.default.existsSync(serverDir)) {
73
+ patterns.push({
74
+ from: serverDir,
75
+ to: distDir,
76
+ tsconfigPath
77
+ });
78
+ }
79
+
80
+ if (_fs.default.existsSync(sharedDir)) {
81
+ patterns.push({
82
+ from: sharedDir,
83
+ to: distDir,
84
+ tsconfigPath
85
+ });
86
+ }
87
+
88
+ if (patterns.length > 0) {
89
+ await compile(appDirectory, modernConfig, {
90
+ patterns
91
+ });
92
+ }
98
93
  }
99
- }
100
94
 
101
- }), {
102
- name: '@modern-js/plugin-server-build'
95
+ })
103
96
  });
104
97
 
105
98
  exports.default = _default;
@@ -1,3 +1,5 @@
1
- declare const _default: any;
1
+ import type { CliPlugin } from '@modern-js/core';
2
+
3
+ declare const _default: () => CliPlugin;
2
4
 
3
5
  export default _default;
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/modern.config.js CHANGED
@@ -1,2 +1,6 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {};
2
+ module.exports = {
3
+ output: {
4
+ packageMode: 'node-js',
5
+ },
6
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.0",
14
+ "version": "1.2.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -29,37 +29,26 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7",
32
- "@modern-js/babel-compiler": "^1.2.0",
33
- "@modern-js/server-utils": "^1.2.0",
34
- "@modern-js/utils": "^1.2.0",
35
- "globby": "^12.0.2",
36
- "json5": "^2.2.0"
32
+ "@modern-js/babel-compiler": "^1.2.2",
33
+ "@modern-js/server-utils": "^1.2.1",
34
+ "@modern-js/utils": "^1.3.6"
37
35
  },
38
36
  "devDependencies": {
39
- "@modern-js/plugin-analyze": "^1.2.0",
37
+ "@modern-js/plugin-analyze": "^1.3.4",
40
38
  "@types/babel__core": "^7.1.15",
41
39
  "@types/jest": "^26",
42
40
  "@types/node": "^14",
43
41
  "ts-jest": "^27.0.5",
44
42
  "typescript": "^4",
45
- "@modern-js/core": "^1.3.0",
43
+ "@modern-js/core": "^1.6.0",
46
44
  "@scripts/build": "0.0.0",
47
45
  "jest": "^27",
48
46
  "@scripts/jest-config": "0.0.0"
49
47
  },
50
- "peerDependencies": {
51
- "@modern-js/core": "^1.3.0"
52
- },
53
48
  "sideEffects": false,
54
- "modernConfig": {
55
- "output": {
56
- "packageMode": "node-js"
57
- }
58
- },
59
49
  "publishConfig": {
60
50
  "registry": "https://registry.npmjs.org/",
61
- "access": "public",
62
- "types": "./dist/types/index.d.ts"
51
+ "access": "public"
63
52
  },
64
53
  "scripts": {
65
54
  "new": "modern new",
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@modern-js/tsconfig/base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "jsx": "preserve",
6
+ "baseUrl": "./",
7
+ "outDir": "./out",
8
+ "emitDeclarationOnly": true,
9
+ "isolatedModules": true,
10
+ "paths": {},
11
+ "types": ["node", "jest"]
12
+ }
13
+ }
package/tsconfig.json CHANGED
@@ -10,5 +10,5 @@
10
10
  "paths": {},
11
11
  "types": ["node", "jest"]
12
12
  },
13
- "include": ["src", "src/.ts"]
13
+ "include": ["src"]
14
14
  }
package/src/index.ts DELETED
@@ -1,98 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import {
4
- createPlugin,
5
- useAppContext,
6
- useResolvedConfigContext,
7
- NormalizedConfig,
8
- } from '@modern-js/core';
9
- import { compiler } from '@modern-js/babel-compiler';
10
- import { resolveBabelConfig } from '@modern-js/server-utils';
11
-
12
- const SERVER_DIR = './server';
13
- const SHARED_DIR = './shared';
14
- const TS_CONFIG_FILENAME = 'tsconfig.json';
15
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
16
-
17
- interface Pattern {
18
- from: string;
19
- to: string;
20
- tsconfigPath?: string;
21
- }
22
-
23
- interface CompileOptions {
24
- patterns: Pattern[];
25
- }
26
-
27
- const compile = async (
28
- appDirectory: string,
29
- modernConfig: NormalizedConfig,
30
- compileOptions: CompileOptions,
31
- ) => {
32
- const { patterns } = compileOptions;
33
- const results = await Promise.all(
34
- patterns.map(pattern => {
35
- const { from, to, tsconfigPath } = pattern;
36
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
37
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
38
- syntax: 'es6+',
39
- type: 'commonjs',
40
- });
41
- return compiler(
42
- {
43
- rootDir: appDirectory,
44
- distDir: to,
45
- sourceDir: from,
46
- extensions: FILE_EXTENSIONS,
47
- },
48
- babelConfig,
49
- );
50
- }),
51
- );
52
- results.forEach(result => {
53
- if (result.code === 1) {
54
- throw new Error(result.message);
55
- }
56
- });
57
- };
58
-
59
- export default createPlugin(
60
- () => ({
61
- config() {
62
- return {};
63
- },
64
- async afterBuild() {
65
- // eslint-disable-next-line react-hooks/rules-of-hooks
66
- const { appDirectory, distDirectory } = useAppContext();
67
- // eslint-disable-next-line react-hooks/rules-of-hooks
68
- const modernConfig = useResolvedConfigContext();
69
-
70
- const distDir = path.resolve(distDirectory);
71
- const serverDir = path.resolve(appDirectory, SERVER_DIR);
72
- const sharedDir = path.resolve(appDirectory, SHARED_DIR);
73
- const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
74
-
75
- const patterns = [];
76
- if (fs.existsSync(serverDir)) {
77
- patterns.push({
78
- from: serverDir,
79
- to: distDir,
80
- tsconfigPath,
81
- });
82
- }
83
-
84
- if (fs.existsSync(sharedDir)) {
85
- patterns.push({
86
- from: sharedDir,
87
- to: distDir,
88
- tsconfigPath,
89
- });
90
- }
91
-
92
- if (patterns.length > 0) {
93
- await compile(appDirectory, modernConfig, { patterns });
94
- }
95
- },
96
- }),
97
- { name: '@modern-js/plugin-server-build' },
98
- ) as any;