@digigov/cli-build 2.0.0-daaf7bdf → 2.0.0-e20fed09

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/index.js CHANGED
@@ -1,107 +1,118 @@
1
- const { Command } = require("@oclif/command");
2
- const execa = require("execa");
3
- const { resolveProject, DigigovCommand } = require("@digigov/cli/lib");
4
- const path = require("path");
5
- const fs = require("fs");
6
- const esbuild = require("esbuild");
7
- const glob = require("glob");
1
+ import { DigigovCommand, resolveProject, logger } from '@digigov/cli/lib';
2
+ import { buildFormat, generateTypeDeclarationFiles } from './build.js';
3
+ import { generateLazyRegistry, generateRegistry } from './generate-registry.js';
4
+ import copyFiles from './copy-files.js';
8
5
 
9
- module.exports = class Build extends DigigovCommand {
10
- static description = "build digigov libraries";
11
- static id = "build";
12
- dirname = __dirname;
13
- static examples = [`$ digigov build`];
14
- static strict = false;
15
- static load() {
16
- return Build;
6
+ import { Option } from 'commander';
7
+ import path from 'path';
8
+ import glob from 'globby';
9
+ import assert from 'assert';
10
+ import { getProjectTsconfig } from './common.js';
11
+
12
+ const command = new DigigovCommand('build', import.meta.url)
13
+ .option(
14
+ '--generate-registry',
15
+ 'Generate a registry file for the build output'
16
+ )
17
+ .addOption(
18
+ new Option('--include-stories', 'Include stories in the output').implies({
19
+ generateRegistry: true,
20
+ })
21
+ )
22
+ .action(main);
23
+ export default command;
24
+
25
+ const SRC_GLOB = 'src/**/*.{tsx,ts,js,jsx}';
26
+ const TEST_GLOBS = [
27
+ '**/*.test.{js,jsx,ts,tsx}',
28
+ '**/*.spec.{js,jsx,ts,tsx}',
29
+ '**/__tests__/**/*.{js,jsx,ts,tsx}',
30
+ ];
31
+ const STORIES_GLOBS = [
32
+ '**/*.stories.{js,jsx,ts,tsx}',
33
+ '**/__stories__/**/*.{js,jsxts,tsx}',
34
+ ];
35
+
36
+ /**
37
+ * @param {object} options - The command options
38
+ * @param {boolean} options.generateRegistry - Generate a registry file for the build output
39
+ * @param {boolean} options.includeStories - Include stories in the generated registry file
40
+ * @param {DigigovCommand} ctx
41
+ */
42
+ async function main(options, ctx) {
43
+ const project = resolveProject();
44
+
45
+ await ctx.exec('rimraf', [project.distDir]);
46
+
47
+ /**
48
+ * The project tsconfig, or undefined if the project is not using TypeScript
49
+ * @type {string | undefined}
50
+ */
51
+ let tsconfig;
52
+ if (project.isTs) {
53
+ tsconfig = getProjectTsconfig(project.root);
54
+ assert(tsconfig, 'Expected tsconfig to be in project');
55
+ await generateTypeDeclarationFiles(project, tsconfig, ctx);
17
56
  }
18
- script = "babel";
19
- async run() {
20
- const { argv } = this.parse(Build);
21
- try {
22
- await this.exec("rimraf", ["dist"]);
23
- const project = resolveProject();
24
- const babelArgs = [
25
- "--config-file",
26
- path.join(__dirname, "babel.config.js"),
27
- project.src,
28
- "--extensions",
29
- ".tsx,.ts,.js,.jsx",
30
- "--copy-files",
31
- "--out-dir",
32
- ];
33
- const distDir = path.resolve(project.root, project.distDir);
34
- const basename = path.basename(project.root);
35
57
 
36
- if (project.isTs) {
37
- const tsconfigProduction = path.join(
38
- project.root,
39
- "tsconfig.production.json",
40
- );
41
- const tsArgs = [];
42
- if (fs.existsSync(tsconfigProduction)) {
43
- tsArgs.push("--project", tsconfigProduction);
44
- }
45
- await this.exec("tsc", [
46
- "--emitDeclarationOnly",
47
- "--outDir",
48
- "dist",
49
- ...tsArgs,
50
- ]);
51
- if (fs.existsSync(path.join(distDir, basename))) {
52
- const typesIncluded = fs.readdirSync(path.join(distDir));
53
- const paths = fs.readdirSync(
54
- path.join(distDir, basename, project.src),
55
- );
56
- paths.forEach((p) => {
57
- fs.renameSync(
58
- path.join(distDir, basename, project.src, p),
59
- path.join(distDir, p),
60
- );
61
- });
62
- typesIncluded.forEach((typesDir) => {
63
- fs.rmSync(path.join(distDir, typesDir), { recursive: true });
64
- });
65
- }
66
- }
58
+ const ignore = [...TEST_GLOBS, ...STORIES_GLOBS];
59
+ const filesToBuild = await glob(path.join(project.root, SRC_GLOB), {
60
+ ignore,
61
+ });
62
+ logger.debug('Bundling ESM and CJS...');
63
+ await Promise.all([
64
+ buildFormat({
65
+ files: filesToBuild,
66
+ tsconfig: tsconfig,
67
+ format: 'cjs',
68
+ outdir: project.distDir + '/cjs',
69
+ }),
70
+ buildFormat({
71
+ files: filesToBuild,
72
+ tsconfig,
73
+ format: 'esm',
74
+ outdir: project.distDir,
75
+ }),
76
+ ]);
77
+ logger.debug('Bundling done.');
67
78
 
68
- const files = glob.sync(
69
- path.join(project.root, "src", "**/*.{tsx,ts,js,jsx}"),
79
+ if (options.generateRegistry) {
80
+ logger.debug('Generating registry files...');
81
+
82
+ const filesToIncludeInRegistry = filesToBuild.filter(
83
+ (file) => !(file.includes('native') || file.endsWith('.d.ts'))
84
+ );
85
+ let storiesFiles = null;
86
+ if (options.includeStories) {
87
+ logger.debug('Including stories in the registry...');
88
+
89
+ storiesFiles = await glob(
90
+ STORIES_GLOBS.map((glob) => path.join(project.root, project.src, glob)),
70
91
  {
71
- ignore: "**/*.{spec,test}.{ts,tsx,js,jsx}",
72
- },
92
+ ignore: ['**/*.native.*, **/*.d.ts'],
93
+ }
73
94
  );
74
- const commonBuildOptions = {
75
- entryPoints: files,
76
- platform: "node",
77
- sourcemap: true,
78
- target: ["esnext"],
79
- logLevel: "error",
80
- };
81
- if (fs.existsSync(path.join(project.root, "tsconfig.production.json"))) {
82
- commonBuildOptions["tsconfig"] = "tsconfig.production.json";
83
- } else if (fs.existsSync(path.join(project.root, "tsconfig.json"))) {
84
- commonBuildOptions["tsconfig"] = "tsconfig.json";
85
- }
86
-
87
- await Promise.all([
88
- esbuild.build({
89
- ...commonBuildOptions,
90
- format: "esm",
91
- outdir: `dist`,
92
- }),
93
- esbuild.build({
94
- ...commonBuildOptions,
95
- format: "cjs",
96
- outdir: `dist/cjs`,
97
- }),
98
- ]);
99
- await execa("node", [path.join(__dirname, "copy-files.js")], {
100
- env: {},
101
- stdio: "inherit",
102
- });
103
- } catch (err) {
104
- console.error(err);
105
95
  }
96
+
97
+ const [, ...registryFilePaths] = await Promise.all([
98
+ storiesFiles
99
+ ? generateRegistry(project, storiesFiles, 'stories-registry.js')
100
+ : null,
101
+ generateRegistry(project, filesToIncludeInRegistry),
102
+ generateLazyRegistry(project, filesToIncludeInRegistry),
103
+ ]);
104
+
105
+ buildFormat({
106
+ files: registryFilePaths,
107
+ tsconfig: tsconfig,
108
+ format: 'cjs',
109
+ outdir: project.distDir + '/cjs',
110
+ noLogs: true,
111
+ });
112
+ logger.log('Generated registry files');
106
113
  }
107
- };
114
+
115
+ logger.debug('Copying files to build directory...');
116
+ copyFiles();
117
+ logger.debug('Files copied.');
118
+ }
package/package.json CHANGED
@@ -1,48 +1,45 @@
1
1
  {
2
2
  "name": "@digigov/cli-build",
3
- "version": "2.0.0-daaf7bdf",
3
+ "version": "2.0.0-e20fed09",
4
4
  "description": "Build plugin for Digigov CLI",
5
5
  "main": "./index.js",
6
+ "type": "module",
6
7
  "author": "GRNET Devs <devs@lists.grnet.gr>",
7
8
  "license": "BSD-2-Clause",
8
9
  "private": false,
9
10
  "dependencies": {
10
- "@babel/cli": "7.12.1",
11
- "@babel/compat-data": "7.12.5",
12
- "@babel/core": "7.12.13",
13
- "@babel/helper-validator-identifier": "7.9.5",
14
- "@babel/plugin-proposal-class-properties": "7.12.1",
15
- "@babel/plugin-proposal-object-rest-spread": "7.12.1",
16
- "@babel/plugin-transform-object-assign": "7.12.1",
17
- "@babel/plugin-transform-runtime": "7.12.1",
18
- "@babel/preset-env": "7.12.13",
19
- "@babel/preset-react": "7.12.13",
20
- "@babel/preset-typescript": "7.12.1",
21
- "babel-plugin-inline-import-data-uri": "1.0.1",
22
- "babel-plugin-module-resolver": "4.0.0",
23
- "babel-plugin-optimize-clsx": "1.1.1",
24
- "babel-plugin-react-remove-properties": "0.3.0",
25
- "babel-plugin-transform-dev-warning": "0.1.1",
26
- "babel-plugin-transform-react-constant-elements": "6.23.0",
27
- "babel-plugin-transform-react-remove-prop-types": "0.4.24",
28
11
  "fs-extra": "11.2.0",
29
- "glob": "7.1.6",
30
- "typescript": "5.6.2",
31
- "@types/node": "18.19.0",
32
- "babel-plugin-istanbul": "7.0.0",
12
+ "globby": "11.0.0",
33
13
  "publint": "0.1.8",
14
+ "rimraf": "3.0.2",
34
15
  "esbuild": "0.23.0",
35
- "@digigov/babel-ts-to-proptypes": "1.1.0"
16
+ "commander": "12.1.0",
17
+ "ts-morph": "25.0.0"
36
18
  },
37
19
  "devDependencies": {
38
- "publint": "0.1.8"
20
+ "@digigov/cli": "2.0.0-e20fed09",
21
+ "@digigov/cli-lint": "2.0.0-e20fed09",
22
+ "publint": "0.1.8",
23
+ "vitest": "2.1.3",
24
+ "@digigov/cli-test": "2.0.0-e20fed09",
25
+ "@types/fs-extra": "11.0.4",
26
+ "@types/node": "20.17.24",
27
+ "typescript": "5.6.2",
28
+ "eslint": "9.16.0",
29
+ "prettier": "3.4.2"
39
30
  },
40
31
  "peerDependencies": {
41
- "@digigov/cli": "1.1.2-daaf7bdf",
42
- "rimraf": "3.0.2",
32
+ "@digigov/cli": "2.0.0-e20fed09",
43
33
  "next": "13.1.1"
44
34
  },
35
+ "peerDependenciesMeta": {
36
+ "next": {
37
+ "optional": true
38
+ }
39
+ },
45
40
  "scripts": {
46
- "publint": "publint"
41
+ "publint": "publint",
42
+ "lint": "digigov lint",
43
+ "typecheck": "tsc"
47
44
  }
48
45
  }
@@ -12,9 +12,6 @@
12
12
  "@digigov/auth/*": ["./auth/src/*"],
13
13
  "@digigov/auth/": ["./auth/src"],
14
14
  "@digigov/auth": ["./auth/src"],
15
- "@digigov/benchmark/*": ["./benchmark/src/*"],
16
- "@digigov/benchmark/": ["./benchmark/src"],
17
- "@digigov/benchmark": ["./benchmark/src"],
18
15
  "@digigov/text-search/*": ["./text-search/src/*"],
19
16
  "@digigov/text-search/": ["./text-search/src"],
20
17
  "@digigov/text-search": ["./text-search/src"],
@@ -36,14 +33,15 @@
36
33
  "@digigov/react-experimental/*": ["../libs-ui/react-experimental/src/*"],
37
34
  "@digigov/react-experimental/": ["../libs-ui/react-experimental/src"],
38
35
  "@digigov/react-experimental": ["../libs-ui/react-experimental/src"],
39
- "@digigov/storybook/*": ["../examples/storybook/stories/*"]
36
+ "@digigov/storybook/*": ["../examples/storybook/stories/*"],
37
+ "@uides/stepwise/*": ["./stepwise/src/*"],
38
+ "@uides/stepwise/": ["./stepwise/src"],
39
+ "@uides/stepwise": ["./stepwise/src"]
40
40
  }
41
41
  },
42
42
  "include": [
43
43
  "../../libs/auth/src/**/*.tsx",
44
44
  "../../libs/auth/src/*.tsx",
45
- "../../libs/benchmark/src/**/*.tsx",
46
- "../../libs/benchmark/src/*.tsx",
47
45
  "../../libs/text-search/src/**/*.tsx",
48
46
  "../../libs/text-search/src/*.tsx",
49
47
  "../../libs/text-search/src/**/*.ts",
package/tsconfig.json CHANGED
@@ -1,45 +1,8 @@
1
1
  {
2
- "extends": "./tsconfig.base.json",
2
+ "extends": "@digigov/cli/tsconfig.cli",
3
3
  "compilerOptions": {
4
- "types": [
5
- "node"
6
- ],
7
- "outDir": "dist",
8
- "paths": {
9
- "@digigov/babel-ts-to-proptypes": [
10
- "node_modules/@digigov/babel-ts-to-proptypes/src"
11
- ],
12
- "@digigov/babel-ts-to-proptypes/": [
13
- "node_modules/@digigov/babel-ts-to-proptypes/src/"
14
- ],
15
- "@digigov/babel-ts-to-proptypes/*": [
16
- "node_modules/@digigov/babel-ts-to-proptypes/src/*"
17
- ],
18
- "@digigov/cli": [
19
- "node_modules/@digigov/cli/src"
20
- ],
21
- "@digigov/cli/": [
22
- "node_modules/@digigov/cli/src/"
23
- ],
24
- "@digigov/cli/*": [
25
- "node_modules/@digigov/cli/src/*"
26
- ],
27
- "@digigov/cli-build": [
28
- "./src"
29
- ],
30
- "@digigov/cli-build/": [
31
- "./src/"
32
- ],
33
- "@digigov/cli-build/*": [
34
- "./src/*"
35
- ]
36
- },
37
- "baseUrl": "./"
4
+ "types": ["vitest/globals"]
38
5
  },
39
- "include": [
40
- "index.js"
41
- ],
42
- "exclude": [
43
- "node_modules"
44
- ]
6
+ "include": ["./*.js", "__tests__"],
7
+ "exclude": ["eslint.config.js", ".prettierrc.cjs"]
45
8
  }
package/babel.common.js 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(null, 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.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./babel.common').config