@ttoss/config 1.35.6 → 1.35.8
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/dist/esm/index.js +82 -37
- package/dist/index.js +82 -37
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __name = (target2, value) => __defProp(target2, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
4
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
5
9
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
6
10
|
exports: {}
|
|
@@ -29,25 +33,25 @@ var require_babel_config = __commonJS({
|
|
|
29
33
|
}]],
|
|
30
34
|
plugins: [
|
|
31
35
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
* Carlin is full ESM and jest doesn't support import.meta.url from
|
|
37
|
+
* @ttoss/cloudformation. This plugin is needed to transform import.meta.url
|
|
38
|
+
*
|
|
39
|
+
* More reference about pure ESM packages:
|
|
40
|
+
* https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
41
|
+
*/
|
|
38
42
|
"babel-plugin-transform-import-meta",
|
|
39
43
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
* This plugin is needed to create a unique ID for each message in the
|
|
45
|
+
* translation files.
|
|
46
|
+
*/
|
|
43
47
|
["formatjs", {
|
|
44
48
|
idInterpolationPattern: "[sha512:contenthash:base64:6]",
|
|
45
49
|
ast: true
|
|
46
50
|
}],
|
|
47
51
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
* Decorators are not supported in ES6, so we need to use this plugin to
|
|
53
|
+
* transpile decorators to ES5.
|
|
54
|
+
*/
|
|
51
55
|
["@babel/plugin-proposal-decorators", {
|
|
52
56
|
version: "legacy"
|
|
53
57
|
}]]
|
|
@@ -57,16 +61,16 @@ var require_babel_config = __commonJS({
|
|
|
57
61
|
|
|
58
62
|
// src/configCreator.ts
|
|
59
63
|
import deepmerge from "deepmerge";
|
|
60
|
-
var overwriteMerge = (_, sourceArray) => {
|
|
64
|
+
var overwriteMerge = /* @__PURE__ */__name((_, sourceArray) => {
|
|
61
65
|
return sourceArray;
|
|
62
|
-
};
|
|
63
|
-
var configCreator = (defaultConfig8 = {}) => {
|
|
66
|
+
}, "overwriteMerge");
|
|
67
|
+
var configCreator = /* @__PURE__ */__name((defaultConfig8 = {}) => {
|
|
64
68
|
return (config = {}, deepmergeConfig) => {
|
|
65
69
|
return deepmerge(defaultConfig8, config, {
|
|
66
70
|
arrayMerge: deepmergeConfig?.arrayMerge === "overwrite" ? overwriteMerge : void 0
|
|
67
71
|
});
|
|
68
72
|
};
|
|
69
|
-
};
|
|
73
|
+
}, "configCreator");
|
|
70
74
|
|
|
71
75
|
// src/babel.ts
|
|
72
76
|
var defaultConfig = require_babel_config();
|
|
@@ -85,25 +89,25 @@ var defaultConfig3 = {
|
|
|
85
89
|
coverageDirectory: "coverage",
|
|
86
90
|
coverageProvider: "babel",
|
|
87
91
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
* https://github.com/jestjs/jest/issues/13739#issuecomment-1517190965
|
|
93
|
+
*/
|
|
90
94
|
extensionsToTreatAsEsm: [".ts", ".tsx"],
|
|
91
95
|
fakeTimers: {
|
|
92
96
|
advanceTimers: true,
|
|
93
97
|
enableGlobally: true
|
|
94
98
|
},
|
|
95
99
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
* https://stackoverflow.com/a/64390115/8786986
|
|
101
|
+
*/
|
|
98
102
|
moduleDirectories: ["node_modules", "<rootDir>/../.."],
|
|
99
103
|
moduleNameMapper: {
|
|
100
104
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
* Remove CSS import errors:
|
|
106
|
+
*
|
|
107
|
+
* Jest failed to parse a file. This happens e.g. when your code or its
|
|
108
|
+
* dependencies use non-standard JavaScript syntax, or when Jest is not
|
|
109
|
+
* configured to support such syntax.
|
|
110
|
+
*/
|
|
107
111
|
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
108
112
|
}
|
|
109
113
|
};
|
|
@@ -147,10 +151,10 @@ var prettierConfig = configCreator(defaultConfig5);
|
|
|
147
151
|
var defaultConfig6 = {
|
|
148
152
|
dependencyTypes: ["dev", "overrides",
|
|
149
153
|
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
* Exclude peer dependencies from the list of dependencies to check
|
|
155
|
+
* to avoid updating peer dependencies to the latest version, as updating
|
|
156
|
+
* React to the latest version instead >=16.8.0.
|
|
157
|
+
*/
|
|
154
158
|
// 'peer',
|
|
155
159
|
"pnpmOverrides", "prod", "resolutions"],
|
|
156
160
|
filter: ".",
|
|
@@ -176,7 +180,7 @@ var target = "es2023";
|
|
|
176
180
|
// src/tsup.ts
|
|
177
181
|
var formatjsPlugin = {
|
|
178
182
|
name: "formatjs",
|
|
179
|
-
setup: build => {
|
|
183
|
+
setup: /* @__PURE__ */__name(build => {
|
|
180
184
|
build.onEnd(async result => {
|
|
181
185
|
await Promise.all((result.outputFiles || []).map(async outputFile => {
|
|
182
186
|
if (!outputFile.path.endsWith(".js") && !outputFile.path.endsWith(".mjs") && !outputFile.path.endsWith(".cjs")) {
|
|
@@ -198,25 +202,66 @@ var formatjsPlugin = {
|
|
|
198
202
|
}
|
|
199
203
|
}));
|
|
200
204
|
});
|
|
201
|
-
}
|
|
205
|
+
}, "setup")
|
|
202
206
|
};
|
|
207
|
+
var injectReactImport = /* @__PURE__ */__name(() => {
|
|
208
|
+
return {
|
|
209
|
+
name: "@ttoss/esbuild-inject-react-import",
|
|
210
|
+
setup: /* @__PURE__ */__name(build => {
|
|
211
|
+
build.onEnd(result => {
|
|
212
|
+
if (result.outputFiles) {
|
|
213
|
+
for (const outputFile of result.outputFiles) {
|
|
214
|
+
if (outputFile.path.endsWith(".js")) {
|
|
215
|
+
let contents = outputFile.text;
|
|
216
|
+
const usesReact = /React\./.test(contents);
|
|
217
|
+
if (usesReact) {
|
|
218
|
+
const hasStarReactImport = /import\s+\*\s+as\s+React\s+from\s+['"]react['"]/.test(contents);
|
|
219
|
+
const hasDefaultReactImport = /import\s+React\s+from\s+['"]react['"]/.test(contents) || /const\s+React\s+=\s+require\(['"]react['"]\)/.test(contents);
|
|
220
|
+
if (!hasStarReactImport && !hasDefaultReactImport) {
|
|
221
|
+
const bannerMatch = contents.match(/^((?:\/\/[^\n]*\n|\/\*[^]*?\*\/)\s*)*/);
|
|
222
|
+
const insertPosition = bannerMatch ? bannerMatch[0].length : 0;
|
|
223
|
+
const isESM = /\bimport\b|\bexport\b/.test(contents);
|
|
224
|
+
const isCJS = /\brequire\(|module\.exports\b/.test(contents);
|
|
225
|
+
const importStatement = (() => {
|
|
226
|
+
if (isESM && !isCJS) {
|
|
227
|
+
return `import * as React from 'react';
|
|
228
|
+
`;
|
|
229
|
+
} else if (isCJS && !isESM) {
|
|
230
|
+
return `const React = require('react');
|
|
231
|
+
`;
|
|
232
|
+
} else {
|
|
233
|
+
return `import * as React from 'react';
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
})();
|
|
237
|
+
contents = contents.slice(0, insertPosition) + importStatement + contents.slice(insertPosition);
|
|
238
|
+
outputFile.contents = new TextEncoder().encode(contents);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}, "setup")
|
|
246
|
+
};
|
|
247
|
+
}, "injectReactImport");
|
|
203
248
|
var defaultConfig7 = {
|
|
204
249
|
clean: true,
|
|
205
250
|
dts: true,
|
|
206
251
|
entryPoints: ["src/index.ts"],
|
|
207
252
|
format: ["cjs", "esm"],
|
|
208
253
|
/**
|
|
209
|
-
|
|
210
|
-
|
|
254
|
+
* legacyOutput `true` because some libraries don't support `.mjs`.
|
|
255
|
+
*/
|
|
211
256
|
legacyOutput: true,
|
|
212
257
|
/**
|
|
213
|
-
|
|
214
|
-
|
|
258
|
+
* Becomes difficult to debug if code is minified.
|
|
259
|
+
*/
|
|
215
260
|
minify: false,
|
|
216
261
|
banner: {
|
|
217
262
|
js: `/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */`
|
|
218
263
|
},
|
|
219
|
-
esbuildPlugins: [formatjsPlugin],
|
|
264
|
+
esbuildPlugins: [formatjsPlugin, injectReactImport()],
|
|
220
265
|
target
|
|
221
266
|
};
|
|
222
267
|
var tsupConfig = configCreator(defaultConfig7);
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __name = (target2, value) => __defProp(target2, "name", {
|
|
11
|
+
value,
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
10
14
|
var __commonJS = (cb, mod) => function __require() {
|
|
11
15
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
12
16
|
exports: {}
|
|
@@ -56,25 +60,25 @@ var require_babel_config = __commonJS({
|
|
|
56
60
|
}]],
|
|
57
61
|
plugins: [
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
* Carlin is full ESM and jest doesn't support import.meta.url from
|
|
64
|
+
* @ttoss/cloudformation. This plugin is needed to transform import.meta.url
|
|
65
|
+
*
|
|
66
|
+
* More reference about pure ESM packages:
|
|
67
|
+
* https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
68
|
+
*/
|
|
65
69
|
"babel-plugin-transform-import-meta",
|
|
66
70
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
* This plugin is needed to create a unique ID for each message in the
|
|
72
|
+
* translation files.
|
|
73
|
+
*/
|
|
70
74
|
["formatjs", {
|
|
71
75
|
idInterpolationPattern: "[sha512:contenthash:base64:6]",
|
|
72
76
|
ast: true
|
|
73
77
|
}],
|
|
74
78
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
* Decorators are not supported in ES6, so we need to use this plugin to
|
|
80
|
+
* transpile decorators to ES5.
|
|
81
|
+
*/
|
|
78
82
|
["@babel/plugin-proposal-decorators", {
|
|
79
83
|
version: "legacy"
|
|
80
84
|
}]]
|
|
@@ -101,16 +105,16 @@ module.exports = __toCommonJS(index_exports);
|
|
|
101
105
|
|
|
102
106
|
// src/configCreator.ts
|
|
103
107
|
var import_deepmerge = __toESM(require("deepmerge"));
|
|
104
|
-
var overwriteMerge = (_, sourceArray) => {
|
|
108
|
+
var overwriteMerge = /* @__PURE__ */__name((_, sourceArray) => {
|
|
105
109
|
return sourceArray;
|
|
106
|
-
};
|
|
107
|
-
var configCreator = (defaultConfig8 = {}) => {
|
|
110
|
+
}, "overwriteMerge");
|
|
111
|
+
var configCreator = /* @__PURE__ */__name((defaultConfig8 = {}) => {
|
|
108
112
|
return (config = {}, deepmergeConfig) => {
|
|
109
113
|
return (0, import_deepmerge.default)(defaultConfig8, config, {
|
|
110
114
|
arrayMerge: deepmergeConfig?.arrayMerge === "overwrite" ? overwriteMerge : void 0
|
|
111
115
|
});
|
|
112
116
|
};
|
|
113
|
-
};
|
|
117
|
+
}, "configCreator");
|
|
114
118
|
|
|
115
119
|
// src/babel.ts
|
|
116
120
|
var defaultConfig = require_babel_config();
|
|
@@ -129,25 +133,25 @@ var defaultConfig3 = {
|
|
|
129
133
|
coverageDirectory: "coverage",
|
|
130
134
|
coverageProvider: "babel",
|
|
131
135
|
/**
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
* https://github.com/jestjs/jest/issues/13739#issuecomment-1517190965
|
|
137
|
+
*/
|
|
134
138
|
extensionsToTreatAsEsm: [".ts", ".tsx"],
|
|
135
139
|
fakeTimers: {
|
|
136
140
|
advanceTimers: true,
|
|
137
141
|
enableGlobally: true
|
|
138
142
|
},
|
|
139
143
|
/**
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
* https://stackoverflow.com/a/64390115/8786986
|
|
145
|
+
*/
|
|
142
146
|
moduleDirectories: ["node_modules", "<rootDir>/../.."],
|
|
143
147
|
moduleNameMapper: {
|
|
144
148
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
* Remove CSS import errors:
|
|
150
|
+
*
|
|
151
|
+
* Jest failed to parse a file. This happens e.g. when your code or its
|
|
152
|
+
* dependencies use non-standard JavaScript syntax, or when Jest is not
|
|
153
|
+
* configured to support such syntax.
|
|
154
|
+
*/
|
|
151
155
|
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
152
156
|
}
|
|
153
157
|
};
|
|
@@ -191,10 +195,10 @@ var prettierConfig = configCreator(defaultConfig5);
|
|
|
191
195
|
var defaultConfig6 = {
|
|
192
196
|
dependencyTypes: ["dev", "overrides",
|
|
193
197
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
* Exclude peer dependencies from the list of dependencies to check
|
|
199
|
+
* to avoid updating peer dependencies to the latest version, as updating
|
|
200
|
+
* React to the latest version instead >=16.8.0.
|
|
201
|
+
*/
|
|
198
202
|
// 'peer',
|
|
199
203
|
"pnpmOverrides", "prod", "resolutions"],
|
|
200
204
|
filter: ".",
|
|
@@ -220,7 +224,7 @@ var target = "es2023";
|
|
|
220
224
|
// src/tsup.ts
|
|
221
225
|
var formatjsPlugin = {
|
|
222
226
|
name: "formatjs",
|
|
223
|
-
setup: build => {
|
|
227
|
+
setup: /* @__PURE__ */__name(build => {
|
|
224
228
|
build.onEnd(async result => {
|
|
225
229
|
await Promise.all((result.outputFiles || []).map(async outputFile => {
|
|
226
230
|
if (!outputFile.path.endsWith(".js") && !outputFile.path.endsWith(".mjs") && !outputFile.path.endsWith(".cjs")) {
|
|
@@ -242,25 +246,66 @@ var formatjsPlugin = {
|
|
|
242
246
|
}
|
|
243
247
|
}));
|
|
244
248
|
});
|
|
245
|
-
}
|
|
249
|
+
}, "setup")
|
|
246
250
|
};
|
|
251
|
+
var injectReactImport = /* @__PURE__ */__name(() => {
|
|
252
|
+
return {
|
|
253
|
+
name: "@ttoss/esbuild-inject-react-import",
|
|
254
|
+
setup: /* @__PURE__ */__name(build => {
|
|
255
|
+
build.onEnd(result => {
|
|
256
|
+
if (result.outputFiles) {
|
|
257
|
+
for (const outputFile of result.outputFiles) {
|
|
258
|
+
if (outputFile.path.endsWith(".js")) {
|
|
259
|
+
let contents = outputFile.text;
|
|
260
|
+
const usesReact = /React\./.test(contents);
|
|
261
|
+
if (usesReact) {
|
|
262
|
+
const hasStarReactImport = /import\s+\*\s+as\s+React\s+from\s+['"]react['"]/.test(contents);
|
|
263
|
+
const hasDefaultReactImport = /import\s+React\s+from\s+['"]react['"]/.test(contents) || /const\s+React\s+=\s+require\(['"]react['"]\)/.test(contents);
|
|
264
|
+
if (!hasStarReactImport && !hasDefaultReactImport) {
|
|
265
|
+
const bannerMatch = contents.match(/^((?:\/\/[^\n]*\n|\/\*[^]*?\*\/)\s*)*/);
|
|
266
|
+
const insertPosition = bannerMatch ? bannerMatch[0].length : 0;
|
|
267
|
+
const isESM = /\bimport\b|\bexport\b/.test(contents);
|
|
268
|
+
const isCJS = /\brequire\(|module\.exports\b/.test(contents);
|
|
269
|
+
const importStatement = (() => {
|
|
270
|
+
if (isESM && !isCJS) {
|
|
271
|
+
return `import * as React from 'react';
|
|
272
|
+
`;
|
|
273
|
+
} else if (isCJS && !isESM) {
|
|
274
|
+
return `const React = require('react');
|
|
275
|
+
`;
|
|
276
|
+
} else {
|
|
277
|
+
return `import * as React from 'react';
|
|
278
|
+
`;
|
|
279
|
+
}
|
|
280
|
+
})();
|
|
281
|
+
contents = contents.slice(0, insertPosition) + importStatement + contents.slice(insertPosition);
|
|
282
|
+
outputFile.contents = new TextEncoder().encode(contents);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}, "setup")
|
|
290
|
+
};
|
|
291
|
+
}, "injectReactImport");
|
|
247
292
|
var defaultConfig7 = {
|
|
248
293
|
clean: true,
|
|
249
294
|
dts: true,
|
|
250
295
|
entryPoints: ["src/index.ts"],
|
|
251
296
|
format: ["cjs", "esm"],
|
|
252
297
|
/**
|
|
253
|
-
|
|
254
|
-
|
|
298
|
+
* legacyOutput `true` because some libraries don't support `.mjs`.
|
|
299
|
+
*/
|
|
255
300
|
legacyOutput: true,
|
|
256
301
|
/**
|
|
257
|
-
|
|
258
|
-
|
|
302
|
+
* Becomes difficult to debug if code is minified.
|
|
303
|
+
*/
|
|
259
304
|
minify: false,
|
|
260
305
|
banner: {
|
|
261
306
|
js: `/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */`
|
|
262
307
|
},
|
|
263
|
-
esbuildPlugins: [formatjsPlugin],
|
|
308
|
+
esbuildPlugins: [formatjsPlugin, injectReactImport()],
|
|
264
309
|
target
|
|
265
310
|
};
|
|
266
311
|
var tsupConfig = configCreator(defaultConfig7);
|