@fontoxml/fontoxml-development-tools 3.9.0-beta.1 → 3.9.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 (24) hide show
  1. package/npm-shrinkwrap.json +17998 -9575
  2. package/package.json +14 -12
  3. package/src/editorVersions.js +23 -0
  4. package/src/modules/editor/src/commands/command.run.controller.js +7 -12
  5. package/src/modules/editor/src/getWebpackConfig.js +178 -33
  6. package/src/modules/editor/src/getWebpackDevMiddlewareConfig.js +16 -9
  7. package/src/modules/editor/src/templates/app-entry.cjs +69 -0
  8. package/src/modules/editor/src/webpackLoaders/generatedLoader.cjs +61 -79
  9. package/src/modules/editor/src/webpackLoaders/platformSourceMapLoader.cjs +7 -4
  10. package/src/modules/editor/src/webpackLoaders/symbolLoader.cjs +7 -7
  11. package/src/modules/editor/src/webpackLoaders/vendorsSourceMapLoader.cjs +5 -3
  12. package/src/modules/editor/src/webpackPlugins/CopyPlugin.js +172 -224
  13. package/src/modules/editor/src/webpackPlugins/DependenciesInLoadOrderPlugin.js +2 -11
  14. package/src/modules/editor/src/webpackPlugins/FdtOutputPlugin.js +102 -95
  15. package/src/modules/editor/src/webpackPlugins/RemoveExplicitExtensionResolvePlugin.js +19 -18
  16. package/src/modules/editor/src/webpackPlugins/ResolveImportAliasPlugin.js +10 -18
  17. package/src/modules/editor/src/webpackPlugins/UnitTestPlugin.js +13 -23
  18. package/src/modules/editor-pre-7-7-0/src/api/init/createConfigConfiguration.js +39 -10
  19. package/src/modules/editor-pre-7-7-0/src/api/schema/buildElementConfigurations.js +70 -0
  20. package/src/modules/editor-pre-7-7-0/src/api/schema/createSchemaExperiencePackages.js +31 -53
  21. package/src/modules/editor-pre-7-7-0/src/command.init.controller.js +4 -2
  22. package/src/modules/editor-pre-7-7-0/test/api/init/createConfigConfiguration.test.js +47 -0
  23. package/src/modules/editor-pre-7-7-0/test/api/schema/buildElementConfigurations.test.js +119 -0
  24. package/src/modules/editor/src/templates/app-entry.ts +0 -66
@@ -1,269 +1,217 @@
1
- /** @typedef {import('webpack').Compiler} Compiler */
2
-
3
1
  import fastGlob from 'fast-glob';
4
2
  import fs from 'fs-extra';
5
3
  import path from 'path';
6
4
  import { fileURLToPath } from 'url';
7
- import webpack from 'webpack';
8
5
 
9
6
  import normalisePath from '../helpers/normalisePath.js';
10
7
 
11
8
  const emittedAssets = new Map();
9
+ const plugin = { name: 'CopyPlugin' };
12
10
 
13
11
  const __filename = fileURLToPath(import.meta.url);
14
12
  const __dirname = path.dirname(__filename);
15
13
 
16
- /**
17
- * This plugin add assets to the compilation which do not exist in the
18
- * dependency tree ('assets' folders of packages).
19
- */
20
14
  export default class CopyPlugin {
21
15
  constructor(options) {
22
16
  this.options = options;
23
17
  }
24
18
 
25
- /**
26
- * @param {Compiler} compiler
27
- */
28
19
  apply(compiler) {
29
20
  let packageInfos;
30
21
 
31
- compiler.hooks.thisCompilation.tap(CopyPlugin.name, (compilation) => {
32
- compilation.hooks.additionalAssets.tapAsync(
33
- CopyPlugin.name,
34
- async (callback) => {
35
- if (
36
- compilation.packagesInfoInLoadOrderError ||
37
- !compilation.packagesInfoInLoadOrder
38
- ) {
39
- const error =
40
- compilation.packagesInfoInLoadOrderError ||
41
- new Error(
42
- 'Could not get package load order information.'
43
- );
44
- packageInfos = error.packageInfos || [];
45
- compilation.errors.push(error);
46
- return callback();
22
+ compiler.hooks.emit.tapAsync(plugin, async (compilation, callback) => {
23
+ if (
24
+ compilation.packagesInfoInLoadOrderError ||
25
+ !compilation.packagesInfoInLoadOrder
26
+ ) {
27
+ const error =
28
+ compilation.packagesInfoInLoadOrderError ||
29
+ new Error('Could not get package load order information.');
30
+ packageInfos = error.packageInfos || [];
31
+ compilation.errors.push(error);
32
+ callback();
33
+ return;
34
+ }
35
+
36
+ const templatesPath = normalisePath(
37
+ path.resolve(__dirname, '..', 'templates')
38
+ );
39
+ const assetInfoByTargetPath = new Map();
40
+
41
+ // TODO: It's not stricly necessary to process these assets every (re)compile.
42
+ // TODO: Consider placing these assets somewhere where they're unlikely to cause conflicts.
43
+ (
44
+ await fastGlob(
45
+ [`${fastGlob.escapePath(templatesPath)}/assets/**/*`],
46
+ {
47
+ absolute: true,
48
+ stats: true,
47
49
  }
48
-
49
- const templatesPath = normalisePath(
50
- path.resolve(__dirname, '..', 'templates')
51
- );
52
- const assetInfoByTargetPath = new Map();
53
-
54
- // TODO: It's not stricly necessary to process these assets
55
- // every (re)compile.
56
- // TODO: Consider placing these assets somewhere where
57
- // they're unlikely to cause conflicts.
58
- (
59
- await fastGlob(
60
- [
61
- `${fastGlob.escapePath(
62
- templatesPath
63
- )}/assets/**/*`,
64
- ],
65
- {
66
- absolute: true,
67
- stats: true,
68
- }
50
+ )
51
+ ).forEach((globResult) => {
52
+ assetInfoByTargetPath.set(
53
+ normalisePath(
54
+ path.relative(templatesPath, globResult.path)
55
+ ),
56
+ {
57
+ path: globResult.path,
58
+ stats: globResult.stats,
59
+ }
60
+ );
61
+ });
62
+
63
+ if (this.options.unitTest) {
64
+ const testAssetsPath = normalisePath(
65
+ path.resolve(this.options.paths.contextFolder)
66
+ );
67
+ (
68
+ await fastGlob(
69
+ [
70
+ `${fastGlob.escapePath(
71
+ testAssetsPath
72
+ )}/test/assets/**/*`,
73
+ ],
74
+ {
75
+ absolute: true,
76
+ stats: true,
77
+ }
78
+ )
79
+ ).forEach((globResult) => {
80
+ const targetPath = normalisePath(
81
+ path.relative(
82
+ path.join(this.options.paths.contextFolder, 'test'),
83
+ globResult.path
69
84
  )
70
- ).forEach((globResult) => {
71
- assetInfoByTargetPath.set(
72
- normalisePath(
73
- path.relative(templatesPath, globResult.path)
74
- ),
75
- {
76
- path: globResult.path,
77
- stats: globResult.stats,
78
- }
79
- );
85
+ );
86
+ assetInfoByTargetPath.set(targetPath, {
87
+ path: globResult.path,
88
+ stats: globResult.stats,
80
89
  });
81
-
82
- if (this.options.unitTest) {
83
- const testAssetsPath = normalisePath(
84
- path.resolve(this.options.paths.contextFolder)
85
- );
86
- (
87
- await fastGlob(
88
- [
89
- `${fastGlob.escapePath(
90
- testAssetsPath
91
- )}/test/assets/**/*`,
92
- ],
93
- {
94
- absolute: true,
95
- stats: true,
96
- }
97
- )
98
- ).forEach((globResult) => {
99
- const targetPath = normalisePath(
100
- path.relative(
101
- path.join(
102
- this.options.paths.contextFolder,
103
- 'test'
104
- ),
105
- globResult.path
106
- )
107
- );
108
- assetInfoByTargetPath.set(targetPath, {
109
- path: globResult.path,
110
- stats: globResult.stats,
111
- });
90
+ });
91
+ }
92
+
93
+ packageInfos = compilation.packagesInfoInLoadOrder;
94
+
95
+ (
96
+ await Promise.all(
97
+ packageInfos.map(async (packageInfo) => {
98
+ const glob =
99
+ fastGlob.escapePath(
100
+ normalisePath(packageInfo.path)
101
+ ) +
102
+ (packageInfo.name === 'config'
103
+ ? '/assets/**/*'
104
+ : '/src/assets/**/*');
105
+
106
+ return await fastGlob([glob], {
107
+ absolute: true,
108
+ stats: true,
112
109
  });
113
- }
114
-
115
- packageInfos = compilation.packagesInfoInLoadOrder;
116
-
117
- (
118
- await Promise.all(
119
- packageInfos.map(async (packageInfo) => {
120
- const glob =
121
- fastGlob.escapePath(
122
- normalisePath(packageInfo.path)
123
- ) +
124
- (packageInfo.name === 'config'
125
- ? '/assets/**/*'
126
- : '/src/assets/**/*');
127
-
128
- return await fastGlob([glob], {
129
- absolute: true,
130
- stats: true,
131
- });
132
- })
110
+ })
111
+ )
112
+ ).reduce((map, globResults) => {
113
+ globResults.forEach((globResult) => {
114
+ const relativePath = normalisePath(
115
+ path.relative(
116
+ this.options.paths.contextFolder,
117
+ globResult.path
133
118
  )
134
- ).reduce((map, globResults) => {
135
- globResults.forEach((globResult) => {
136
- const relativePath = normalisePath(
137
- path.relative(
138
- this.options.paths.contextFolder,
139
- globResult.path
140
- )
141
- );
142
- const pathParts = relativePath.split(
143
- path.posix.sep
144
- );
145
- const isRootPackage =
146
- relativePath.startsWith('config') ||
147
- (this.options.unitTest &&
148
- relativePath.startsWith('src/'));
149
- const targetPath = path.posix.join(
150
- ...pathParts.slice(isRootPackage ? 1 : 3)
151
- );
152
-
153
- map.set(targetPath, {
154
- path: globResult.path,
155
- stats: globResult.stats,
156
- });
157
- });
119
+ );
120
+ const pathParts = relativePath.split(path.posix.sep);
121
+ const isRootPackage =
122
+ relativePath.startsWith('config') ||
123
+ (this.options.unitTest &&
124
+ relativePath.startsWith('src/'));
125
+ const targetPath = path.posix.join(
126
+ ...pathParts.slice(isRootPackage ? 1 : 3)
127
+ );
158
128
 
159
- return map;
160
- }, assetInfoByTargetPath);
129
+ map.set(targetPath, {
130
+ path: globResult.path,
131
+ stats: globResult.stats,
132
+ });
133
+ });
161
134
 
162
- await Promise.all(
163
- [...emittedAssets.keys()].map(async (targetPath) => {
164
- if (!assetInfoByTargetPath.has(targetPath)) {
165
- const assetOutputPath = path.join(
166
- compilation.getPath(compiler.outputPath),
167
- targetPath
168
- );
135
+ return map;
136
+ }, assetInfoByTargetPath);
169
137
 
170
- await new Promise((resolve, reject) =>
171
- compiler.outputFileSystem.unlink(
172
- assetOutputPath,
173
- (error) =>
174
- error ? reject(error) : resolve()
175
- )
176
- );
138
+ await Promise.all(
139
+ [...emittedAssets.keys()].map(async (targetPath) => {
140
+ if (!assetInfoByTargetPath.has(targetPath)) {
141
+ const assetOutputPath = path.join(
142
+ compilation.getPath(compiler.outputPath),
143
+ targetPath
144
+ );
177
145
 
178
- emittedAssets.delete(targetPath);
179
- }
180
- })
181
- );
146
+ await new Promise((resolve, reject) =>
147
+ compiler.outputFileSystem.unlink(
148
+ assetOutputPath,
149
+ (error) => (error ? reject(error) : resolve())
150
+ )
151
+ );
182
152
 
183
- await Promise.all(
184
- [...assetInfoByTargetPath.keys()].map(
185
- async (targetPath) => {
186
- const assetInfo =
187
- assetInfoByTargetPath.get(targetPath);
153
+ emittedAssets.delete(targetPath);
154
+ }
155
+ })
156
+ );
188
157
 
189
- if (
190
- emittedAssets.has(targetPath) &&
191
- emittedAssets.get(targetPath).path ===
192
- assetInfo.path &&
193
- emittedAssets.get(targetPath).stats
194
- .mtimeMs === assetInfo.stats.mtimeMs
195
- ) {
196
- return;
197
- }
158
+ await Promise.all(
159
+ [...assetInfoByTargetPath.keys()].map(async (targetPath) => {
160
+ const assetInfo = assetInfoByTargetPath.get(targetPath);
198
161
 
199
- emittedAssets.set(targetPath, assetInfo);
162
+ if (
163
+ emittedAssets.has(targetPath) &&
164
+ emittedAssets.get(targetPath).path === assetInfo.path &&
165
+ emittedAssets.get(targetPath).stats.mtimeMs ===
166
+ assetInfo.stats.mtimeMs
167
+ ) {
168
+ return;
169
+ }
200
170
 
201
- const content = await fs.readFile(
202
- assetInfo.path
203
- );
171
+ emittedAssets.set(targetPath, assetInfo);
204
172
 
205
- compilation.emitAsset(
206
- targetPath,
207
- new webpack.sources.RawSource(content)
208
- );
209
- }
210
- )
211
- );
173
+ const content = await fs.readFile(assetInfo.path);
212
174
 
213
- return callback();
214
- }
175
+ compilation.assets[targetPath] = {
176
+ size() {
177
+ return assetInfo.stats.size;
178
+ },
179
+ source() {
180
+ return content;
181
+ },
182
+ };
183
+ })
215
184
  );
216
185
 
217
- compiler.hooks.afterEmit.tapAsync(
218
- CopyPlugin.name,
219
- async (compilation, callback) => {
220
- const platformPath = path.normalize(
221
- this.options.paths.platformFolder
222
- );
186
+ callback();
187
+ });
188
+
189
+ compiler.hooks.afterEmit.tapAsync(plugin, (compilation, callback) => {
190
+ const platformPath = path.normalize(
191
+ this.options.paths.platformFolder
192
+ );
223
193
 
224
- await Promise.all(
225
- packageInfos.map(async (packageInfo) => {
226
- const packagePath = path.normalize(
227
- packageInfo.path
228
- );
194
+ // TODO: Consider checking if the assets folder/manifest file exists before watching.
195
+ packageInfos.forEach((packageInfo) => {
196
+ const packagePath = path.normalize(packageInfo.path);
229
197
 
230
- if (
231
- packagePath ===
232
- path.join(platformPath, packageInfo.name)
233
- ) {
234
- return;
235
- }
198
+ if (packagePath === path.join(platformPath, packageInfo.name)) {
199
+ return;
200
+ }
236
201
 
237
- compilation.contextDependencies.add(
238
- path.join(
239
- packagePath,
240
- packageInfo.name === 'config' ? '' : 'src'
241
- )
242
- );
202
+ compilation.contextDependencies.add(
203
+ path.join(
204
+ packagePath,
205
+ packageInfo.name === 'config' ? 'assets' : 'src/assets'
206
+ )
207
+ );
243
208
 
244
- const fontoManifestPath = path.join(
245
- packagePath,
246
- 'fonto-manifest.json'
247
- );
248
- const exists = await fs
249
- .access(fontoManifestPath)
250
- .then(() => true)
251
- .catch(() => false);
252
- if (exists) {
253
- compilation.fileDependencies.add(
254
- fontoManifestPath
255
- );
256
- } else {
257
- compilation.missingDependencies.add(
258
- fontoManifestPath
259
- );
260
- }
261
- })
262
- );
209
+ compilation.fileDependencies.add(
210
+ path.join(packagePath, 'fonto-manifest.json')
211
+ );
212
+ });
263
213
 
264
- return callback();
265
- }
266
- );
214
+ callback();
267
215
  });
268
216
  }
269
217
  }
@@ -1,24 +1,15 @@
1
- /** @typedef {import('webpack').Compiler} Compiler */
2
-
3
1
  import getDependenciesInLoadOrder from '../getDependenciesInLoadOrder.js';
4
2
 
5
- /**
6
- * This plugin exposes Fonto Editor's dependency tree through webpack's
7
- * compilation objects for use by other plugins.
8
- */
9
3
  export default class DependenciesInLoadOrderPlugin {
10
4
  constructor(options) {
11
5
  this.options = options;
12
6
  }
13
7
 
14
- /**
15
- * @param {Compiler} compiler
16
- */
17
8
  apply(compiler) {
18
9
  // Listen to thisCompilation hook and get dependencies in load order once per compilation.
19
10
  compiler.hooks.thisCompilation.tap(
20
- DependenciesInLoadOrderPlugin.name,
21
- (compilation) => {
11
+ 'DependenciesInLoadOrderPlugin',
12
+ (compilation, _compilationParams) => {
22
13
  try {
23
14
  const packageRootFolders =
24
15
  this.options.paths.packageRootFolders;