@digigov/cli-build 2.0.0-rc.21 → 2.0.0-rc.22

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.
@@ -1,17 +1,16 @@
1
1
  {
2
- "../../tooling/cli-build": "../../tooling/cli-build:pAQsXnAQMf4lndbj9ZmjcYLifQhoD25kjbbi+6xqg1c=:",
3
- "/@babel/cli@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
2
+ "../../tooling/cli-build": "../../tooling/cli-build:o90YTy4xQCi6KeWvf5LX25kGiIgP/Xhcx0CMi+Wmhog=:",
3
+ "/@babel/cli@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
4
4
  "/@babel/compat-data@7.12.5": "Missing shrinkwrap entry!",
5
- "/@babel/core@7.12.13": "Missing shrinkwrap entry!",
5
+ "/@babel/core@7.26.0": "Missing shrinkwrap entry!",
6
6
  "/@babel/helper-validator-identifier@7.9.5": "Missing shrinkwrap entry!",
7
- "/@babel/plugin-proposal-class-properties@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
8
- "/@babel/plugin-proposal-object-rest-spread@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
9
- "/@babel/plugin-transform-object-assign@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
10
- "/@babel/plugin-transform-runtime@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
11
- "/@babel/preset-env@7.12.13(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
12
- "/@babel/preset-react@7.12.13(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
13
- "/@babel/preset-typescript@7.12.1(@babel/core@7.12.13)": "Missing shrinkwrap entry!",
14
- "/@types/node@18.19.0": "Missing shrinkwrap entry!",
7
+ "/@babel/plugin-proposal-class-properties@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
8
+ "/@babel/plugin-proposal-object-rest-spread@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
9
+ "/@babel/plugin-transform-object-assign@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
10
+ "/@babel/plugin-transform-runtime@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
11
+ "/@babel/preset-env@7.12.13(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
12
+ "/@babel/preset-react@7.12.13(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
13
+ "/@babel/preset-typescript@7.12.1(@babel/core@7.26.0)": "Missing shrinkwrap entry!",
15
14
  "/babel-plugin-inline-import-data-uri@1.0.1": "Missing shrinkwrap entry!",
16
15
  "/babel-plugin-istanbul@7.0.0": "Missing shrinkwrap entry!",
17
16
  "/babel-plugin-module-resolver@4.0.0": "Missing shrinkwrap entry!",
@@ -22,9 +21,8 @@
22
21
  "/babel-plugin-transform-react-remove-prop-types@0.4.24": "Missing shrinkwrap entry!",
23
22
  "/esbuild@0.23.0": "Missing shrinkwrap entry!",
24
23
  "/fs-extra@11.2.0": "Missing shrinkwrap entry!",
25
- "/glob@7.1.6": "Missing shrinkwrap entry!",
26
- "/next@13.1.1(@babel/core@7.12.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)": "Missing shrinkwrap entry!",
24
+ "/globby@11.0.0": "Missing shrinkwrap entry!",
25
+ "/next@13.1.1(@babel/core@7.26.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)": "Missing shrinkwrap entry!",
27
26
  "/publint@0.1.8": "Missing shrinkwrap entry!",
28
- "/rimraf@3.0.2": "Missing shrinkwrap entry!",
29
- "/typescript@5.6.2": "Missing shrinkwrap entry!"
27
+ "/rimraf@3.0.2": "Missing shrinkwrap entry!"
30
28
  }
@@ -4,7 +4,7 @@ const lib = require("@digigov/cli/lib");
4
4
 
5
5
  function makeBabelConfig(dir, opts = { docs: false, proptypes: false }) {
6
6
  const project = lib.resolveProject(dir);
7
- const aliases = !project.externalLockFile ? lib.aliases(null, true) : {};
7
+ const aliases = !project.externalLockFile ? lib.aliases(true) : {};
8
8
 
9
9
  const BABEL_ENV = process.env.BABEL_ENV || "esm";
10
10
  const BABEL_PUBLISH = process.env.BABEL_PUBLISH || false;
@@ -0,0 +1 @@
1
+ module.exports = require("./babel.common.cjs").config;
package/copy-files.js CHANGED
@@ -1,23 +1,33 @@
1
- /* eslint-disable no-console */
2
- const path = require("path");
3
- const fs = require("fs");
4
- const fse = require("fs-extra");
5
- const glob = require("glob");
6
- const { resolveProject } = require("@digigov/cli/lib");
1
+ import { logger, resolveProject } from "@digigov/cli/lib";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import glob from "globby";
7
5
 
8
- const project = resolveProject();
9
6
  const packagePath = process.cwd();
10
- const buildPath = path.join(project.root, project.distDir);
11
7
 
12
- async function includeFileInBuild(file) {
8
+ function getBuildPath() {
9
+ const project = resolveProject();
10
+ return path.join(project.root, project.distDir);
11
+ }
12
+
13
+ /**
14
+ * Copy a file from the package to the build directory
15
+ *
16
+ * @param {string} file - The file to include in the build
17
+ */
18
+ function includeFileInBuild(file) {
13
19
  const sourcePath = path.resolve(packagePath, file);
20
+ const buildPath = getBuildPath();
14
21
  const targetPath = path.resolve(buildPath, path.basename(file));
15
- await fse.copy(sourcePath, targetPath);
16
- console.log(`Copied ${sourcePath} to ${targetPath}`);
22
+ fs.copySync(sourcePath, targetPath);
23
+ logger.log(`Copied ${sourcePath} to ${targetPath}`);
17
24
  }
18
25
 
19
- async function createRootPackageFile() {
20
- const packageData = await fse.readFile(
26
+ /**
27
+ * Create a package.json file in the build directory
28
+ */
29
+ function createRootPackageFile() {
30
+ const packageData = fs.readFileSync(
21
31
  path.resolve(packagePath, "./package.json"),
22
32
  "utf8",
23
33
  );
@@ -30,20 +40,24 @@ async function createRootPackageFile() {
30
40
  module: "./index.js",
31
41
  typings: "./index.d.ts",
32
42
  };
43
+ const buildPath = getBuildPath();
33
44
  const targetPath = path.resolve(buildPath, "./package.json");
34
45
 
35
- await fse.writeFile(
36
- targetPath,
37
- JSON.stringify(newPackageData, null, 2),
38
- "utf8",
39
- );
40
- console.log(`Created package.json in ${targetPath}`);
46
+ fs.writeFileSync(targetPath, JSON.stringify(newPackageData, null, 2), "utf8");
47
+ logger.log(`Created package.json in ${targetPath}`);
41
48
 
42
49
  return newPackageData;
43
50
  }
44
51
 
52
+ /**
53
+ * Create nested package.json files in the build directory
54
+ *
55
+ */
45
56
  function createNestedPackageFiles() {
46
- const indexPaths = glob.sync(path.join(buildPath, "!(cjs)/**/index.js"));
57
+ const buildPath = getBuildPath();
58
+ const indexPaths = glob.sync(path.join(buildPath, "**/index.js"), {
59
+ ignore: [path.join(buildPath, "cjs/**")],
60
+ });
47
61
 
48
62
  indexPaths.forEach((indexPath) => {
49
63
  if (indexPath === path.join(buildPath, "index.js")) return;
@@ -63,63 +77,78 @@ function createNestedPackageFiles() {
63
77
  });
64
78
  }
65
79
 
66
- async function prepend(file, string) {
67
- const data = await fse.readFile(file, "utf8");
68
- await fse.writeFile(file, string + data, "utf8");
80
+ /**
81
+ * Prepend a string to a file
82
+ *
83
+ * @param {string} file - The file to prepend to
84
+ * @param {string} string - The string to prepend
85
+ */
86
+ function prepend(file, string) {
87
+ const data = fs.readFileSync(file, "utf8");
88
+ fs.writeFileSync(file, string + data, "utf8");
69
89
  }
70
90
 
71
- async function addLicense(packageData) {
72
- const license = `/** @license Digigov v${packageData.version}
91
+ /**
92
+ * Add license to the top of the files
93
+ *
94
+ * @param {object} packageData - The package data
95
+ */
96
+ function addLicense(packageData) {
97
+ const buildPath = getBuildPath();
98
+ const license = `/** @license Digigov v${packageData["version"]}
73
99
  *
74
100
  * This source code is licensed under the BSD-2-Clause license found in the
75
101
  * LICENSE file in the root directory of this source tree.
76
102
  */
77
103
  `;
78
- await Promise.all(
79
- ["./index.js", "./index.mjs"].map(async (file) => {
80
- try {
81
- await prepend(path.resolve(buildPath, file), license);
82
- } catch (err) {
83
- if (err.code === "ENOENT") {
84
- console.log(`Skipped license for ${file}`);
85
- } else {
86
- throw err;
87
- }
104
+ ["./index.js", "./index.mjs"].map(async (file) => {
105
+ try {
106
+ prepend(path.resolve(buildPath, file), license);
107
+ } catch (err) {
108
+ if (
109
+ typeof err === "object" &&
110
+ err &&
111
+ "code" in err &&
112
+ err.code === "ENOENT"
113
+ ) {
114
+ logger.log(`Skipped license for ${file}`);
115
+ } else {
116
+ throw err;
88
117
  }
89
- }),
90
- );
118
+ }
119
+ });
91
120
  }
92
121
 
122
+ /**
123
+ * Create separate index modules for each directory
124
+ */
93
125
  function createSeparateIndexModules() {
94
- const files = glob.sync(path.join(buildPath, "**/!(index).js"));
126
+ const buildPath = getBuildPath();
127
+ const files = glob.sync(path.join(buildPath, "**/*.js"), {
128
+ ignore: [path.join(buildPath, "**/index.js")],
129
+ });
95
130
 
96
131
  files.forEach((file) => {
97
- fs.mkdirSync(file.replace(".js", ""));
98
- fs.renameSync(file, file.replace(".js", "/index.js"));
132
+ fs.mkdirSync(file.replace(/\.js$/, ""));
133
+ fs.renameSync(file, file.replace(/\.js$/, "/index.js"));
99
134
  });
100
135
  }
101
136
 
102
- async function run() {
103
- try {
104
- const packageData = await createRootPackageFile();
105
- createSeparateIndexModules();
106
- createNestedPackageFiles();
107
-
108
- await Promise.all(
109
- [
110
- // use enhanced readme from workspace root for `@digigov/ui`
111
- // packageData.name === '@digigov/ui' ? '../../README.md' : './README.md',
112
- "./src",
113
- "./README.md",
114
- "./CHANGELOG.md",
115
- "../../LICENSE",
116
- ].map((file) => includeFileInBuild(file)),
117
- );
137
+ /**
138
+ * Run the copy files script
139
+ */
140
+ export default function run() {
141
+ const packageData = createRootPackageFile();
142
+ createSeparateIndexModules();
143
+ createNestedPackageFiles();
118
144
 
119
- await addLicense(packageData);
120
- } catch (err) {
121
- console.error(err);
122
- }
145
+ [
146
+ // use enhanced readme from workspace root for `@digigov/ui`
147
+ // packageData.name === '@digigov/ui' ? '../../README.md' : './README.md',
148
+ "./src",
149
+ "./README.md",
150
+ "./CHANGELOG.md",
151
+ "../../LICENSE",
152
+ ].map((file) => includeFileInBuild(file)),
153
+ addLicense(packageData);
123
154
  }
124
-
125
- run();
package/index.js CHANGED
@@ -1,107 +1,85 @@
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 } from "@digigov/cli/lib";
2
+ import copyFiles from "./copy-files.js";
8
3
 
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;
17
- }
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);
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import esbuild from "esbuild";
7
+ import glob from "globby";
35
8
 
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
- }
9
+ const command = new DigigovCommand("build", import.meta.url).action(build);
10
+ export default command;
11
+
12
+ /**
13
+ * @param {DigigovCommand} ctx
14
+ */
15
+ async function build(_, ctx) {
16
+ await ctx.exec("rimraf", ["dist"]);
17
+ const project = resolveProject();
67
18
 
68
- const files = glob.sync(
69
- path.join(project.root, "src", "**/*.{tsx,ts,js,jsx}"),
70
- {
71
- ignore: "**/*.{spec,test}.{ts,tsx,js,jsx}",
72
- },
73
- );
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
- }
19
+ const distDir = path.resolve(project.root, project.distDir);
20
+ const basename = path.basename(project.root);
86
21
 
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",
22
+ if (project.isTs) {
23
+ const tsconfigProduction = path.join(
24
+ project.root,
25
+ "tsconfig.production.json",
26
+ );
27
+ /** @type {string[]} */
28
+ const tsArgs = [];
29
+ if (fs.existsSync(tsconfigProduction)) {
30
+ tsArgs.push("--project", tsconfigProduction);
31
+ }
32
+ await ctx.exec("tsc", [
33
+ "--emitDeclarationOnly",
34
+ "--outDir",
35
+ "dist",
36
+ ...tsArgs,
37
+ ]);
38
+ if (fs.existsSync(path.join(distDir, basename))) {
39
+ const typesIncluded = fs.readdirSync(path.join(distDir));
40
+ const paths = fs.readdirSync(path.join(distDir, basename, project.src));
41
+ paths.forEach((p) => {
42
+ fs.renameSync(
43
+ path.join(distDir, basename, project.src, p),
44
+ path.join(distDir, p),
45
+ );
46
+ });
47
+ typesIncluded.forEach((typesDir) => {
48
+ fs.rmSync(path.join(distDir, typesDir), { recursive: true });
102
49
  });
103
- } catch (err) {
104
- console.error(err);
105
50
  }
106
51
  }
107
- };
52
+
53
+ const files = glob.sync(
54
+ path.join(project.root, "src", "**/*.{tsx,ts,js,jsx}"),
55
+ {
56
+ ignore: ["**/*.{spec,test}.{ts,tsx,js,jsx}"],
57
+ },
58
+ );
59
+ const commonBuildOptions = {
60
+ entryPoints: files,
61
+ platform: "node",
62
+ sourcemap: true,
63
+ target: ["esnext"],
64
+ logLevel: "error",
65
+ };
66
+ if (fs.existsSync(path.join(project.root, "tsconfig.production.json"))) {
67
+ commonBuildOptions["tsconfig"] = "tsconfig.production.json";
68
+ } else if (fs.existsSync(path.join(project.root, "tsconfig.json"))) {
69
+ commonBuildOptions["tsconfig"] = "tsconfig.json";
70
+ }
71
+
72
+ await Promise.all([
73
+ esbuild.build({
74
+ ...commonBuildOptions,
75
+ format: "esm",
76
+ outdir: `dist`,
77
+ }),
78
+ esbuild.build({
79
+ ...commonBuildOptions,
80
+ format: "cjs",
81
+ outdir: `dist/cjs`,
82
+ }),
83
+ ]);
84
+ copyFiles();
85
+ }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@digigov/cli-build",
3
- "version": "2.0.0-rc.21",
3
+ "version": "2.0.0-rc.22",
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
11
  "@babel/cli": "7.12.1",
11
12
  "@babel/compat-data": "7.12.5",
12
- "@babel/core": "7.12.13",
13
+ "@babel/core": "7.26.0",
13
14
  "@babel/helper-validator-identifier": "7.9.5",
14
15
  "@babel/plugin-proposal-class-properties": "7.12.1",
15
16
  "@babel/plugin-proposal-object-rest-spread": "7.12.1",
@@ -26,22 +27,25 @@
26
27
  "babel-plugin-transform-react-constant-elements": "6.23.0",
27
28
  "babel-plugin-transform-react-remove-prop-types": "0.4.24",
28
29
  "fs-extra": "11.2.0",
29
- "glob": "7.1.6",
30
- "typescript": "5.6.2",
31
- "@digigov/babel-ts-to-proptypes": "1.1.0-rc.19-rc.20-rc.21",
32
- "@types/node": "18.19.0",
30
+ "globby": "11.0.0",
31
+ "@digigov/babel-ts-to-proptypes": "1.1.0-rc.22",
33
32
  "babel-plugin-istanbul": "7.0.0",
34
33
  "publint": "0.1.8",
34
+ "rimraf": "3.0.2",
35
35
  "esbuild": "0.23.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "publint": "0.1.8"
39
39
  },
40
40
  "peerDependencies": {
41
- "@digigov/cli": "1.1.1-rc.21",
42
- "rimraf": "3.0.2",
41
+ "@digigov/cli": "2.0.0-rc.22",
43
42
  "next": "13.1.1"
44
43
  },
44
+ "peerDependenciesMeta": {
45
+ "next": {
46
+ "optional": true
47
+ }
48
+ },
45
49
  "scripts": {
46
50
  "publint": "publint"
47
51
  }
@@ -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"],
@@ -42,8 +39,6 @@
42
39
  "include": [
43
40
  "../../libs/auth/src/**/*.tsx",
44
41
  "../../libs/auth/src/*.tsx",
45
- "../../libs/benchmark/src/**/*.tsx",
46
- "../../libs/benchmark/src/*.tsx",
47
42
  "../../libs/text-search/src/**/*.tsx",
48
43
  "../../libs/text-search/src/*.tsx",
49
44
  "../../libs/text-search/src/**/*.ts",
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./babel.common').config
package/tsconfig.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
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": "./"
38
- },
39
- "include": [
40
- "index.js"
41
- ],
42
- "exclude": [
43
- "node_modules"
44
- ]
45
- }