@digigov/cli-build 2.0.0-07ee8440 → 2.0.0-0b806366
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/.prettierrc.cjs +1 -0
- package/.rush/temp/shrinkwrap-deps.json +427 -32
- package/common.js +3 -3
- package/copy-files.js +26 -79
- package/eslint.config.js +3 -0
- package/generate-registry.js +96 -149
- package/index.js +151 -81
- package/package.json +14 -27
- package/transform-imports-plugin.js +263 -0
- package/tsconfig.base.json +21 -59
- package/tsconfig.json +3 -7
- package/babel.common.cjs +0 -119
- package/babel.config.cjs +0 -1
- package/build.js +0 -85
- package/tsconfig.common.json +0 -27
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@digigov/cli/tsconfig.cli",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"types": [
|
|
5
|
-
"vitest/globals"
|
|
6
|
-
]
|
|
4
|
+
"types": ["vitest/globals"]
|
|
7
5
|
},
|
|
8
|
-
"include": [
|
|
9
|
-
|
|
10
|
-
"__tests__"
|
|
11
|
-
]
|
|
6
|
+
"include": ["./*.js", "__tests__"],
|
|
7
|
+
"exclude": ["eslint.config.js", ".prettierrc.cjs"]
|
|
12
8
|
}
|
package/babel.common.cjs
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// Mostly shared from
|
|
2
|
-
// https://github.com/mui-org/material-ui/blob/master/babel.config.js
|
|
3
|
-
const lib = require("@digigov/cli/lib");
|
|
4
|
-
|
|
5
|
-
function makeBabelConfig(dir, opts = { docs: false, proptypes: false }) {
|
|
6
|
-
const project = lib.resolveProject(dir);
|
|
7
|
-
const aliases = !project.externalLockFile ? lib.aliases(true) : {};
|
|
8
|
-
|
|
9
|
-
const BABEL_ENV = process.env.BABEL_ENV || "esm";
|
|
10
|
-
const BABEL_PUBLISH = process.env.BABEL_PUBLISH || false;
|
|
11
|
-
const NODE_ENV = process.env.NODE_ENV;
|
|
12
|
-
const IS_COMMONJS = BABEL_ENV === "cjs" || NODE_ENV === "test";
|
|
13
|
-
|
|
14
|
-
const PRESETS = [
|
|
15
|
-
[
|
|
16
|
-
require.resolve("@babel/preset-env"),
|
|
17
|
-
{
|
|
18
|
-
modules: IS_COMMONJS ? "commonjs" : false,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
require.resolve("@babel/preset-react"),
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
if (project.isTs) {
|
|
25
|
-
PRESETS.push(require.resolve("@babel/preset-typescript"));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const PLUGINS_COMMON = [
|
|
29
|
-
require.resolve("babel-plugin-optimize-clsx"),
|
|
30
|
-
[
|
|
31
|
-
require.resolve("@babel/plugin-proposal-class-properties"),
|
|
32
|
-
{ loose: true },
|
|
33
|
-
],
|
|
34
|
-
[
|
|
35
|
-
require.resolve("@babel/plugin-proposal-object-rest-spread"),
|
|
36
|
-
{ loose: true },
|
|
37
|
-
],
|
|
38
|
-
// any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0
|
|
39
|
-
[require.resolve("@babel/plugin-transform-runtime"), { version: "^7.4.4" }],
|
|
40
|
-
// for IE 11 support
|
|
41
|
-
require.resolve("@babel/plugin-transform-object-assign"),
|
|
42
|
-
require.resolve("babel-plugin-transform-react-constant-elements"),
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
const PLUGINS_PUBLISH = [
|
|
46
|
-
require.resolve("babel-plugin-transform-dev-warning"),
|
|
47
|
-
[
|
|
48
|
-
require.resolve("babel-plugin-react-remove-properties"),
|
|
49
|
-
{ properties: ["data-testid"] },
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
require.resolve("babel-plugin-transform-react-remove-prop-types"),
|
|
53
|
-
{
|
|
54
|
-
mode: "unsafe-wrap",
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
const PLUGINS = PLUGINS_COMMON;
|
|
60
|
-
|
|
61
|
-
// Apps images are handled using `next-images` plugin. For libraries there is no
|
|
62
|
-
// explicit way to provide assets to the App using the library. While not
|
|
63
|
-
// considered a very good practice, one way to provide images via libraries is
|
|
64
|
-
// to embed the image data into the library code.
|
|
65
|
-
if (project.isLib || project.isApp) {
|
|
66
|
-
PLUGINS.push(require.resolve("babel-plugin-inline-import-data-uri"));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (BABEL_PUBLISH) {
|
|
70
|
-
PLUGINS.push(...PLUGINS_PUBLISH);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!opts.docs) {
|
|
74
|
-
let resolverAlias = {};
|
|
75
|
-
if (NODE_ENV === "test") resolverAlias = aliases;
|
|
76
|
-
if (BABEL_ENV === "cjs") {
|
|
77
|
-
resolverAlias = Object.keys(aliases).reduce((acc, key) => {
|
|
78
|
-
if (key !== project.name) {
|
|
79
|
-
acc[`^${key}/(.+)`] = `${key}/cjs/\\1`;
|
|
80
|
-
}
|
|
81
|
-
return acc;
|
|
82
|
-
}, {});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const RESOLVER = [
|
|
86
|
-
require.resolve("babel-plugin-module-resolver"),
|
|
87
|
-
{
|
|
88
|
-
alias: resolverAlias,
|
|
89
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".json"],
|
|
90
|
-
loglevel: "silent",
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
PLUGINS.push(RESOLVER);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (project.isApp) {
|
|
97
|
-
PRESETS.push(require.resolve("next/babel"));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const CONFIG = {
|
|
101
|
-
presets: PRESETS,
|
|
102
|
-
plugins: PLUGINS,
|
|
103
|
-
ignore: [/@babel[\\|/]runtime/],
|
|
104
|
-
env: {
|
|
105
|
-
coverage: {
|
|
106
|
-
plugins: [require.resolve("babel-plugin-istanbul")],
|
|
107
|
-
},
|
|
108
|
-
test: {
|
|
109
|
-
sourceMaps: "both",
|
|
110
|
-
plugins: [],
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
return CONFIG;
|
|
115
|
-
}
|
|
116
|
-
module.exports = {
|
|
117
|
-
makeBabelConfig,
|
|
118
|
-
config: makeBabelConfig(),
|
|
119
|
-
};
|
package/babel.config.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./babel.common.cjs").config;
|
package/build.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { DigigovCommand, logger } from "@digigov/cli/lib";
|
|
2
|
-
|
|
3
|
-
import assert from "assert";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import fs from "fs-extra";
|
|
6
|
-
import baseEsbuild from "esbuild";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Generate TypeScript declaration files
|
|
10
|
-
*
|
|
11
|
-
* @param {object} project - The project object
|
|
12
|
-
* @param {string} project.root - The project root directory
|
|
13
|
-
* @param {string} project.src - The project source directory
|
|
14
|
-
* @param {string} project.distDir - The project build directory
|
|
15
|
-
* @param {string} tsconfig - The tsconfig path
|
|
16
|
-
* @param {DigigovCommand} ctx - The command context
|
|
17
|
-
*/
|
|
18
|
-
export async function generateTypeDeclarationFiles(project, tsconfig, ctx) {
|
|
19
|
-
logger.debug("Building types...");
|
|
20
|
-
|
|
21
|
-
const distDir = path.resolve(project.root, project.distDir);
|
|
22
|
-
const projectBasename = path.basename(project.root);
|
|
23
|
-
|
|
24
|
-
await ctx.exec("tsc", [
|
|
25
|
-
"--emitDeclarationOnly",
|
|
26
|
-
"--outDir",
|
|
27
|
-
"dist",
|
|
28
|
-
"--project",
|
|
29
|
-
tsconfig,
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
const projectBasePath = path.join(distDir, projectBasename);
|
|
33
|
-
logger.debug("Project base path", projectBasePath);
|
|
34
|
-
if (await fs.exists(projectBasePath)) {
|
|
35
|
-
const typesIncluded = await fs.readdir(path.join(distDir));
|
|
36
|
-
const srcPath = path.join(distDir, projectBasename, project.src);
|
|
37
|
-
const paths = await fs.readdir(srcPath);
|
|
38
|
-
|
|
39
|
-
await Promise.all([
|
|
40
|
-
// Move src files to dist
|
|
41
|
-
...paths.map((p) => {
|
|
42
|
-
logger.debug("Moving types file", p);
|
|
43
|
-
fs.move(path.join(srcPath, p), path.join(distDir, p));
|
|
44
|
-
}),
|
|
45
|
-
// Remove dirs
|
|
46
|
-
...typesIncluded.map((typesDir) => {
|
|
47
|
-
logger.debug("Removing types directory", typesDir);
|
|
48
|
-
fs.rm(path.join(distDir, typesDir), { recursive: true });
|
|
49
|
-
}),
|
|
50
|
-
]).catch((err) => {
|
|
51
|
-
logger.error("Error while building types", err);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
logger.debug("Types built.");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Run esbuild for the given options
|
|
59
|
-
*
|
|
60
|
-
* @param {object} options - The build options
|
|
61
|
-
* @param {string[]} options.files - The files to build
|
|
62
|
-
* @param {string | undefined} options.tsconfig - The tsconfig path
|
|
63
|
-
* @param {"esm" | "cjs"} options.format - The module format
|
|
64
|
-
* @param {string} options.outdir - The output directory
|
|
65
|
-
*/
|
|
66
|
-
export function buildFormat({ files: entryPoints, tsconfig, format, outdir }) {
|
|
67
|
-
assert(format === "esm" || format === "cjs", "Invalid format");
|
|
68
|
-
|
|
69
|
-
logger.log(`Running: esbuild for ${format.toUpperCase()} format`);
|
|
70
|
-
return baseEsbuild.build({
|
|
71
|
-
...BASE_OPTIONS,
|
|
72
|
-
entryPoints,
|
|
73
|
-
tsconfig,
|
|
74
|
-
format,
|
|
75
|
-
outdir,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** @type {baseEsbuild.BuildOptions} */
|
|
80
|
-
export const BASE_OPTIONS = {
|
|
81
|
-
logLevel: "error",
|
|
82
|
-
platform: "node",
|
|
83
|
-
sourcemap: true,
|
|
84
|
-
target: ["esnext"],
|
|
85
|
-
};
|
package/tsconfig.common.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "ESNext",
|
|
4
|
-
"target": "es5",
|
|
5
|
-
"lib": [
|
|
6
|
-
"es6",
|
|
7
|
-
"dom",
|
|
8
|
-
"es2019"
|
|
9
|
-
],
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"allowJs": true,
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"moduleResolution": "node",
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"noImplicitReturns": true,
|
|
17
|
-
"noImplicitThis": true,
|
|
18
|
-
"noImplicitAny": false,
|
|
19
|
-
"strictNullChecks": true,
|
|
20
|
-
"noUnusedLocals": true,
|
|
21
|
-
"noUnusedParameters": true,
|
|
22
|
-
"allowSyntheticDefaultImports": true,
|
|
23
|
-
"skipDefaultLibCheck": true,
|
|
24
|
-
"skipLibCheck": true,
|
|
25
|
-
"resolveJsonModule": true
|
|
26
|
-
}
|
|
27
|
-
}
|