sugar-scripts 0.2.0-beta.0 → 1.0.0-beta.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.
Files changed (90) hide show
  1. package/lib/bin/cli-ts.d.ts +1 -0
  2. package/lib/bin/cli-ts.js +4 -0
  3. package/lib/bin/cli-ts.js.map +1 -0
  4. package/lib/bin/cli.d.ts +1 -0
  5. package/lib/bin/cli.js +4 -0
  6. package/lib/bin/cli.js.map +1 -0
  7. package/lib/commander/index.d.ts +1 -0
  8. package/lib/commander/index.js +79 -0
  9. package/lib/commander/index.js.map +1 -0
  10. package/lib/constants/index.d.ts +4 -0
  11. package/lib/constants/index.js +8 -0
  12. package/lib/constants/index.js.map +1 -0
  13. package/lib/core/build.d.ts +2 -0
  14. package/lib/core/build.js +74 -0
  15. package/lib/core/build.js.map +1 -0
  16. package/lib/core/cache.d.ts +2 -0
  17. package/lib/core/cache.js +9 -0
  18. package/lib/core/cache.js.map +1 -0
  19. package/lib/core/info.d.ts +1 -0
  20. package/lib/core/info.js +6 -0
  21. package/lib/core/info.js.map +1 -0
  22. package/lib/core/init-running-context.d.ts +2 -0
  23. package/lib/core/init-running-context.js +30 -0
  24. package/lib/core/init-running-context.js.map +1 -0
  25. package/lib/core/run-application.d.ts +2 -0
  26. package/lib/core/run-application.js +9 -0
  27. package/lib/core/run-application.js.map +1 -0
  28. package/lib/core/running-context.d.ts +23 -0
  29. package/lib/core/running-context.js +52 -0
  30. package/lib/core/running-context.js.map +1 -0
  31. package/lib/custom-config.type.d.ts +51 -0
  32. package/lib/custom-config.type.js +8 -0
  33. package/lib/custom-config.type.js.map +1 -0
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +6 -0
  36. package/lib/index.js.map +1 -0
  37. package/lib/shared/file-helpers.d.ts +18 -0
  38. package/lib/shared/file-helpers.js +227 -0
  39. package/lib/shared/file-helpers.js.map +1 -0
  40. package/lib/webpack/dll-dependencies-manifest-plugin.d.ts +15 -0
  41. package/lib/webpack/dll-dependencies-manifest-plugin.js +79 -0
  42. package/lib/webpack/dll-dependencies-manifest-plugin.js.map +1 -0
  43. package/lib/webpack/load-manifest.d.ts +11 -0
  44. package/lib/webpack/load-manifest.js +47 -0
  45. package/lib/webpack/load-manifest.js.map +1 -0
  46. package/lib/webpack/run-webpack.d.ts +2 -0
  47. package/lib/webpack/run-webpack.js +23 -0
  48. package/lib/webpack/run-webpack.js.map +1 -0
  49. package/lib/webpack/server-browser-entry.d.ts +12 -0
  50. package/lib/webpack/server-browser-entry.js +41 -0
  51. package/lib/webpack/server-browser-entry.js.map +1 -0
  52. package/lib/webpack/webpack.browser.d.ts +4 -0
  53. package/lib/webpack/webpack.browser.js +88 -0
  54. package/lib/webpack/webpack.browser.js.map +1 -0
  55. package/lib/webpack/webpack.common.d.ts +7 -0
  56. package/lib/webpack/webpack.common.js +80 -0
  57. package/lib/webpack/webpack.common.js.map +1 -0
  58. package/lib/webpack/webpack.server.d.ts +4 -0
  59. package/lib/webpack/webpack.server.js +74 -0
  60. package/lib/webpack/webpack.server.js.map +1 -0
  61. package/package.json +17 -32
  62. package/src/bin/cli-ts.ts +3 -0
  63. package/src/index.ts +0 -3
  64. package/CHANGELOG.md +0 -26
  65. package/bin/cli-ts.js +0 -3
  66. package/bin/cli.js +0 -3
  67. package/src/app-utils/index.ts +0 -1
  68. package/src/app-utils/static.ts +0 -42
  69. package/src/commander/index.ts +0 -95
  70. package/src/configs/babel.server.config.ts +0 -42
  71. package/src/configs/babel.static.config.ts +0 -43
  72. package/src/constants/index.ts +0 -5
  73. package/src/core/build.ts +0 -98
  74. package/src/core/cache.ts +0 -15
  75. package/src/core/entry.ts +0 -189
  76. package/src/core/info.ts +0 -5
  77. package/src/core/init-running-context.ts +0 -27
  78. package/src/core/run-application.ts +0 -12
  79. package/src/core/running-context.ts +0 -92
  80. package/src/custom-config.type.ts +0 -66
  81. package/src/shared/file-helpers.ts +0 -192
  82. package/src/typings.d.ts +0 -8
  83. package/src/webpack/auto-entries.ts +0 -5
  84. package/src/webpack/dll-dependencies-manifest-plugin.ts +0 -115
  85. package/src/webpack/load-manifest.ts +0 -73
  86. package/src/webpack/run-webpack.ts +0 -22
  87. package/src/webpack/webpack.browser.ts +0 -107
  88. package/src/webpack/webpack.common.ts +0 -146
  89. package/src/webpack/webpack.server.ts +0 -100
  90. package/tsconfig.json +0 -25
@@ -1,73 +0,0 @@
1
- import path from 'path';
2
-
3
- import {
4
- searchFiles,
5
- findParentFile,
6
- loadJSON
7
- } from '../shared/file-helpers';
8
-
9
- export async function loadAllDllModulesManifest (
10
- dir: string,
11
- exclude?: string
12
- ): Promise<{
13
- context: string;
14
- manifest: {
15
- name: string;
16
- content: any;
17
- };
18
- moduleName: string;
19
- name: string;
20
- assets: string[]
21
- }[]> {
22
- const moduleFilePaths = await searchFiles(
23
- dir,
24
- 'dll.modules.manifest.json',
25
- exclude
26
- );
27
-
28
- const modules = await Promise.all(
29
- moduleFilePaths.map(async (moduleFilePath) => {
30
- const moduleConfigFilePath = await findParentFile(
31
- moduleFilePath,
32
- 'manifest.json'
33
- );
34
- if (!moduleConfigFilePath) {
35
- throw new Error(`not find manifest.json for ${moduleFilePath}`)
36
- }
37
- const moduleConfig = await loadJSON(moduleConfigFilePath);
38
- const module = await loadJSON(moduleFilePath);
39
- const name = module.name.split('_sn_').slice(1).join('_sn_');
40
- return {
41
- context: moduleConfig.context,
42
- manifest: module,
43
- moduleName: module.name,
44
- name,
45
- assets: moduleConfig.entries[name]
46
- }
47
- })
48
- )
49
-
50
- return modules.filter((module) => !!module) as {
51
- context: string;
52
- manifest: {
53
- name: string;
54
- content: any;
55
- };
56
- moduleName: string;
57
- name: string;
58
- assets: string[]
59
- }[];
60
- }
61
-
62
- export async function loadBaseManifest (
63
- dir: string,
64
- rootHash: string
65
- ) {
66
- return loadJSON(
67
- path.resolve(
68
- dir,
69
- rootHash,
70
- './manifest.json'
71
- )
72
- );
73
- }
@@ -1,22 +0,0 @@
1
- import webpack from 'webpack';
2
- import WebpackChainConfig from 'webpack-chain';
3
-
4
-
5
- export const runWebpack = (
6
- chainConfig: WebpackChainConfig
7
- ) => {
8
- const compiler = webpack(
9
- chainConfig.toConfig()
10
- );
11
-
12
- return new Promise((resolve, reject) => {
13
- compiler.run((err, stats) => {
14
- if (err || stats && stats.hasErrors()) {
15
- reject(err || stats?.toString())
16
- return;
17
- }
18
- console.log(stats?.toString())
19
- resolve(stats)
20
- })
21
- })
22
- }
@@ -1,107 +0,0 @@
1
- import path from 'path';
2
- import webpack from 'webpack';
3
- import WebpackChainConfig from 'webpack-chain';
4
-
5
- import {
6
- SugarScriptsContext
7
- } from '../core/running-context';
8
- import {
9
- getEntriesFromApplicationClass
10
- } from '../core/entry';
11
-
12
- import {
13
- loadCustomConfig
14
- } from './webpack.common';
15
- import {
16
- SUGAR_BUILD_EXPORT_BROWSER
17
- } from '../constants'
18
-
19
-
20
- export async function mergeBrowserEntryFromServer(
21
- context: SugarScriptsContext,
22
- chainConfig: WebpackChainConfig
23
- ) {
24
- if (!context.packageConfig.browser) return;
25
- const browserConfig = context.packageConfig.browser;
26
-
27
- if (browserConfig.input) {
28
- const App = require(
29
- path.resolve(
30
- context.root,
31
- browserConfig.input
32
- )
33
- ).default;
34
-
35
- const configEntry = getEntriesFromApplicationClass(
36
- App,
37
- context.root
38
- );
39
-
40
- const normalizeEntry = (entryPath: string) => {
41
- return path.resolve(context.root, entryPath);
42
- }
43
- Object.keys(configEntry)
44
- .forEach((entryKey) => {
45
- const entryPath = configEntry[entryKey];
46
- if (typeof entryPath === 'string') {
47
- chainConfig.entry(entryKey)
48
- .add(normalizeEntry(entryPath))
49
- }
50
- });
51
- }
52
- if (browserConfig.entry) {
53
- const entry = browserConfig.entry;
54
- Object.keys(entry)
55
- .forEach((entryKey) => {
56
- const entryPath = entry[entryKey];
57
- if (Array.isArray(entryPath)) {
58
- chainConfig.entry(entryKey)
59
- .merge(entryPath)
60
- } else {
61
- chainConfig.entry(entryKey)
62
- .add(entryPath)
63
- }
64
- });
65
- }
66
- }
67
-
68
-
69
- export async function mergeBuildDllConfig (
70
- context: SugarScriptsContext,
71
- chainConfig: WebpackChainConfig
72
- ) {
73
- if (!context.packageConfig.browser) return;
74
- const browserConfig = context.packageConfig.browser;
75
-
76
- if (browserConfig.dll) {
77
- chainConfig.output
78
- .library(`${context.rootHash}_sn_[name]`)
79
- .libraryTarget('umd');
80
-
81
- chainConfig.plugin('DllPlugin')
82
- .use(
83
- webpack.DllPlugin,
84
- [{
85
- context: context.root,
86
- name: `${context.rootHash}_sn_[name]`,
87
- path: path.resolve(
88
- context.getCacheDir(),
89
- context.rootHash,
90
- './[name]/dll.modules.manifest.json'
91
- ),
92
- format: true
93
- }]
94
- );
95
- }
96
- }
97
-
98
- export async function mergeBrowserCustomConfig (
99
- context: SugarScriptsContext,
100
- chainConfig: WebpackChainConfig
101
- ) {
102
- await loadCustomConfig(
103
- context,
104
- chainConfig,
105
- SUGAR_BUILD_EXPORT_BROWSER
106
- )
107
- }
@@ -1,146 +0,0 @@
1
- import path from 'path';
2
- import webpack from 'webpack';
3
- import WebpackChainConfig from 'webpack-chain';
4
-
5
- import {
6
- loadAllDllModulesManifest
7
- } from './load-manifest';
8
- import {
9
- SugarScriptsContext
10
- } from '../core/running-context';
11
- import {
12
- DllDependenciesManifestPlugin
13
- } from './dll-dependencies-manifest-plugin'
14
- import {
15
- SUGAR_PACKAGE_CONFIG_FILENAME
16
- } from '../constants'
17
-
18
- // const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production';
19
- const mode = 'development';
20
-
21
- /**
22
- * common 是创建基础的webpack配置项,基于webpack-chain
23
- * 用于被 webpack.dll 、webpack.frontend、webpack.server扩展
24
- */
25
-
26
- export async function createCommonChainConfig (
27
- context: SugarScriptsContext,
28
- output: string
29
- ): Promise<WebpackChainConfig> {
30
- let chainConfig = new WebpackChainConfig();
31
-
32
- chainConfig.merge({
33
- context: context.root,
34
- resolve: {
35
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.svg', '.png', '.jpg', '.gif'],
36
- },
37
- output: {
38
- path: path.resolve(
39
- context.root,
40
- output || 'dist'
41
- ),
42
- filename:
43
- mode === 'development'
44
- ? '[name].js'
45
- : '[name].[contenthash].js'
46
- },
47
- mode,
48
- optimization: {
49
- moduleIds: 'named',
50
- chunkIds: 'named'
51
- },
52
- stats: true,
53
- module: {
54
- rule: {
55
- script: {
56
- test: /\.(ts|tsx|js|jsx)$/,
57
- use: {
58
- 'ts-loader': {
59
- loader: 'ts-loader',
60
- options: {
61
- transpileOnly: true
62
- }
63
- }
64
- }
65
- }
66
- },
67
- },
68
- plugin: {
69
- 'ProgressPlugin': {
70
- plugin: webpack.ProgressPlugin,
71
- args: []
72
- }
73
- }
74
- })
75
-
76
- return chainConfig;
77
- }
78
-
79
- export async function loadCustomConfig (
80
- context: SugarScriptsContext,
81
- chainConfig: WebpackChainConfig,
82
- customFnName: string
83
- ) {
84
- let custom: any;
85
- try {
86
- custom = require(
87
- path.resolve(
88
- context.root,
89
- SUGAR_PACKAGE_CONFIG_FILENAME
90
- )
91
- )[customFnName];
92
- } catch(e) {}
93
- if (custom) {
94
- await custom(chainConfig, context);
95
- }
96
- }
97
-
98
-
99
- export async function mergeDllReferences (
100
- context: SugarScriptsContext,
101
- chainConfig: WebpackChainConfig,
102
- ) {
103
- const dllModules = await loadAllDllModulesManifest(
104
- context.getCacheDir(),
105
- context.rootHash
106
- );
107
-
108
- const dllAssets = dllModules.reduce((dllAssets, dllModule) => {
109
- dllAssets[dllModule.moduleName] = dllModule.assets;
110
- return dllAssets;
111
- }, {} as {
112
- [dllName: string]: string[];
113
- })
114
-
115
- dllModules.forEach((
116
- module
117
- ) => {
118
- chainConfig.plugin(module.moduleName)
119
- .use(
120
- webpack.DllReferencePlugin,
121
- [{
122
- context: module.context,
123
- manifest: module.manifest
124
- }]
125
- );
126
- })
127
-
128
- chainConfig.plugin('DllDependenciesManifestPlugin')
129
- .use(
130
- DllDependenciesManifestPlugin,
131
- [{
132
- dllAssets,
133
- fileName: path.resolve(
134
- context.getCacheDir(),
135
- context.rootHash,
136
- './manifest.json'
137
- ),
138
- generate: (entries: any) => {
139
- return {
140
- context: context.root,
141
- entries
142
- };
143
- }
144
- }]
145
- );
146
- }
@@ -1,100 +0,0 @@
1
- import path from 'path';
2
- import webpack from 'webpack';
3
- import WebpackChainConfig from 'webpack-chain';
4
-
5
- import {
6
- loadBaseManifest
7
- } from './load-manifest';
8
- import {
9
- SugarScriptsContext
10
- } from '../core/running-context';
11
- import {
12
- loadCustomConfig
13
- } from './webpack.common';
14
- import {
15
- SUGAR_BUILD_EXPORT_SERVER
16
- } from '../constants'
17
-
18
- export async function mergeServerEntry (
19
- context: SugarScriptsContext,
20
- chainConfig: WebpackChainConfig
21
- ) {
22
- if (!context.packageConfig.server) return;
23
- const serverConfig = context.packageConfig.server;
24
-
25
- chainConfig.entry('main')
26
- .merge(
27
- [
28
- serverConfig.render || '',
29
- serverConfig.entry,
30
- path.resolve(__dirname, 'auto-entries.ts')
31
- ].filter((path) => !!path) as string[]
32
- );
33
-
34
- const manifest = await loadBaseManifest(
35
- context.getCacheDir(),
36
- context.rootHash
37
- );
38
-
39
- chainConfig.merge({
40
- target: 'node',
41
- output: {
42
- filename: '[name].js',
43
- library: {
44
- // name: 'main',
45
- type: 'commonjs',
46
- // export: 'default',
47
- }
48
- },
49
- resolve: {
50
- mainFields: [
51
- 'sugar-scripts-main',
52
- 'main'
53
- ]
54
- },
55
- externalsPresets: { node: true },
56
- externals: serverConfig.dll ? function ({ context, request }: any, callback: any) {
57
- console.log(request, context);
58
- if (/^[^./]{1}/.test(request)) {
59
- console.log('commonjs', request)
60
- // Externalize to a commonjs module using the request path
61
- return callback(null, request, 'commonjs');
62
- }
63
- callback();
64
- }: undefined,
65
- plugin: {
66
- 'DefinePlugin': {
67
- plugin: webpack.DefinePlugin,
68
- args: [{
69
- 'process.env.SUGAR_PROJECT_REAL_ENTRY': JSON.stringify(
70
- path.resolve(
71
- context.root,
72
- serverConfig.entry
73
- )
74
- ),
75
- 'process.env.SUGAR_PROJECT_RUN': JSON.stringify(true),
76
- 'process.env.SUGAR_PROJECT_CONTEXT': JSON.stringify(manifest.context),
77
- 'process.env.SUGAR_PROJECT_RENDER': JSON.stringify(
78
- serverConfig.render
79
- && path.resolve(
80
- context.root,
81
- serverConfig.render
82
- )
83
- ),
84
- 'process.env.SUGAR_PROJECT_ENTRIES': JSON.stringify(manifest.entries),
85
- }]
86
- }
87
- }
88
- })
89
- }
90
-
91
- export async function mergeServerCustomConfig (
92
- context: SugarScriptsContext,
93
- chainConfig: WebpackChainConfig
94
- ) {
95
- await loadCustomConfig(
96
- context,
97
- chainConfig,
98
- SUGAR_BUILD_EXPORT_SERVER
99
- )
100
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "CommonJS",
5
- "strict": true,
6
- "allowJs": false,
7
- "jsx": "react",
8
- "declaration": true,
9
- "esModuleInterop": true,
10
- "moduleResolution": "node",
11
- "experimentalDecorators": true,
12
- "emitDecoratorMetadata": true,
13
- "allowSyntheticDefaultImports": true,
14
- "resolveJsonModule": true,
15
- "lib": [
16
- "ESNext",
17
- "DOM"
18
- ],
19
- "skipLibCheck": true,
20
- "sourceMap": true,
21
- "outDir": "lib",
22
- "baseUrl": ".",
23
- "rootDir": "src",
24
- }
25
- }