@digigov/cli-build 2.0.0-d0adc9fb → 2.0.0-d2ffc726

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,36 +1,36 @@
1
- import { DigigovCommand, resolveProject, logger } from "@digigov/cli/lib";
2
- import { buildFormat, generateTypeDeclarationFiles } from "./build.js";
3
- import { generateRegistryFiles } from "./generate-registry.js";
4
- import copyFiles from "./copy-files.js";
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';
5
5
 
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";
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
11
 
12
- const command = new DigigovCommand("build", import.meta.url)
12
+ const command = new DigigovCommand('build', import.meta.url)
13
13
  .option(
14
- "--generate-registry",
15
- "Generate a registry file for the build output",
14
+ '--generate-registry',
15
+ 'Generate a registry file for the build output'
16
16
  )
17
17
  .addOption(
18
- new Option("--include-stories", "Include stories in the output").implies({
18
+ new Option('--include-stories', 'Include stories in the output').implies({
19
19
  generateRegistry: true,
20
- }),
20
+ })
21
21
  )
22
22
  .action(main);
23
23
  export default command;
24
24
 
25
- const SRC_GLOB = "src/**/*.{tsx,ts,js,jsx}";
25
+ const SRC_GLOB = 'src/**/*.{tsx,ts,js,jsx}';
26
26
  const TEST_GLOBS = [
27
- "**/*.test.{js,jsx,ts,tsx}",
28
- "**/*.spec.{js,jsx,ts,tsx}",
29
- "**/__tests__/**/*.{js,jsx,ts,tsx}",
27
+ '**/*.test.{js,jsx,ts,tsx}',
28
+ '**/*.spec.{js,jsx,ts,tsx}',
29
+ '**/__tests__/**/*.{js,jsx,ts,tsx}',
30
30
  ];
31
31
  const STORIES_GLOBS = [
32
- "**/*.stories.{js,jsx,ts,tsx}",
33
- "**/__stories__/**/*.{js,jsxts,tsx}",
32
+ '**/*.stories.{js,jsx,ts,tsx}',
33
+ '**/__stories__/**/*.{js,jsxts,tsx}',
34
34
  ];
35
35
 
36
36
  /**
@@ -42,7 +42,7 @@ const STORIES_GLOBS = [
42
42
  async function main(options, ctx) {
43
43
  const project = resolveProject();
44
44
 
45
- await ctx.exec("rimraf", [project.distDir]);
45
+ await ctx.exec('rimraf', [project.distDir]);
46
46
 
47
47
  /**
48
48
  * The project tsconfig, or undefined if the project is not using TypeScript
@@ -51,56 +51,68 @@ async function main(options, ctx) {
51
51
  let tsconfig;
52
52
  if (project.isTs) {
53
53
  tsconfig = getProjectTsconfig(project.root);
54
- assert(tsconfig, "Expected tsconfig to be in project");
54
+ assert(tsconfig, 'Expected tsconfig to be in project');
55
55
  await generateTypeDeclarationFiles(project, tsconfig, ctx);
56
56
  }
57
57
 
58
- const ignore = [...TEST_GLOBS];
59
- if (options.includeStories) {
60
- logger.debug("Including stories in the build");
61
- } else {
62
- ignore.push(...STORIES_GLOBS);
63
- }
58
+ const ignore = [...TEST_GLOBS, ...STORIES_GLOBS];
64
59
  const filesToBuild = await glob(path.join(project.root, SRC_GLOB), {
65
60
  ignore,
66
61
  });
67
- logger.debug("Bundling ESM and CJS...");
62
+ logger.debug('Bundling ESM and CJS...');
68
63
  await Promise.all([
69
64
  buildFormat({
70
65
  files: filesToBuild,
71
66
  tsconfig: tsconfig,
72
- format: "cjs",
73
- outdir: project.distDir + "/cjs",
67
+ format: 'cjs',
68
+ outdir: project.distDir + '/cjs',
74
69
  }),
75
70
  buildFormat({
76
71
  files: filesToBuild,
77
72
  tsconfig,
78
- format: "esm",
73
+ format: 'esm',
79
74
  outdir: project.distDir,
80
75
  }),
81
76
  ]);
82
- logger.debug("Bundling done.");
77
+ logger.debug('Bundling done.');
83
78
 
84
79
  if (options.generateRegistry) {
85
- const registryFiles = filesToBuild.filter(
86
- (file) => !(file.includes("native") || file.endsWith(".d.ts")),
87
- );
88
- logger.debug("Generating registry files...");
89
- const registryFilePaths = await generateRegistryFiles(
90
- project,
91
- registryFiles,
92
- options.includeStories,
80
+ logger.debug('Generating registry files...');
81
+
82
+ const filesToIncludeInRegistry = filesToBuild.filter(
83
+ (file) => !(file.includes('native') || file.endsWith('.d.ts'))
93
84
  );
94
- await buildFormat({
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)),
91
+ {
92
+ ignore: ['**/*.native.*, **/*.d.ts'],
93
+ }
94
+ );
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({
95
106
  files: registryFilePaths,
96
107
  tsconfig: tsconfig,
97
- format: "cjs",
98
- outdir: project.distDir + "/cjs",
108
+ format: 'cjs',
109
+ outdir: project.distDir + '/cjs',
110
+ noLogs: true,
99
111
  });
100
- logger.log("Generated registry files");
112
+ logger.log('Generated registry files');
101
113
  }
102
114
 
103
- logger.debug("Copying files to build directory...");
115
+ logger.debug('Copying files to build directory...');
104
116
  copyFiles();
105
- logger.debug("Files copied.");
117
+ logger.debug('Files copied.');
106
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digigov/cli-build",
3
- "version": "2.0.0-d0adc9fb",
3
+ "version": "2.0.0-d2ffc726",
4
4
  "description": "Build plugin for Digigov CLI",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -8,27 +8,8 @@
8
8
  "license": "BSD-2-Clause",
9
9
  "private": false,
10
10
  "dependencies": {
11
- "@babel/cli": "7.12.1",
12
- "@babel/compat-data": "7.12.5",
13
- "@babel/core": "7.26.0",
14
- "@babel/helper-validator-identifier": "7.9.5",
15
- "@babel/plugin-proposal-class-properties": "7.12.1",
16
- "@babel/plugin-proposal-object-rest-spread": "7.12.1",
17
- "@babel/plugin-transform-object-assign": "7.12.1",
18
- "@babel/plugin-transform-runtime": "7.12.1",
19
- "@babel/preset-env": "7.12.13",
20
- "@babel/preset-react": "7.12.13",
21
- "@babel/preset-typescript": "7.12.1",
22
- "babel-plugin-inline-import-data-uri": "1.0.1",
23
- "babel-plugin-module-resolver": "4.0.0",
24
- "babel-plugin-optimize-clsx": "1.1.1",
25
- "babel-plugin-react-remove-properties": "0.3.0",
26
- "babel-plugin-transform-dev-warning": "0.1.1",
27
- "babel-plugin-transform-react-constant-elements": "6.23.0",
28
- "babel-plugin-transform-react-remove-prop-types": "0.4.24",
29
11
  "fs-extra": "11.2.0",
30
12
  "globby": "11.0.0",
31
- "babel-plugin-istanbul": "7.0.0",
32
13
  "publint": "0.1.8",
33
14
  "rimraf": "3.0.2",
34
15
  "esbuild": "0.23.0",
@@ -36,15 +17,19 @@
36
17
  "ts-morph": "25.0.0"
37
18
  },
38
19
  "devDependencies": {
20
+ "@digigov/cli": "2.0.0-d2ffc726",
21
+ "@digigov/cli-lint": "2.0.0-d2ffc726",
39
22
  "publint": "0.1.8",
40
23
  "vitest": "2.1.3",
41
- "@digigov/cli-test": "2.0.0-d0adc9fb",
24
+ "@digigov/cli-test": "2.0.0-d2ffc726",
42
25
  "@types/fs-extra": "11.0.4",
43
- "@types/node": "18.19.0",
44
- "typescript": "5.6.2"
26
+ "@types/node": "20.17.24",
27
+ "typescript": "5.6.2",
28
+ "eslint": "9.16.0",
29
+ "prettier": "3.4.2"
45
30
  },
46
31
  "peerDependencies": {
47
- "@digigov/cli": "2.0.0-d0adc9fb",
32
+ "@digigov/cli": "2.0.0-d2ffc726",
48
33
  "next": "13.1.1"
49
34
  },
50
35
  "peerDependenciesMeta": {
@@ -53,6 +38,8 @@
53
38
  }
54
39
  },
55
40
  "scripts": {
56
- "publint": "publint"
41
+ "publint": "publint",
42
+ "lint": "digigov lint",
43
+ "typecheck": "tsc"
57
44
  }
58
45
  }
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
- "./*.js",
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;