@forsakringskassan/vite-lib-config 4.6.9 → 4.7.1

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/README.md CHANGED
@@ -5,6 +5,7 @@ Toolchain for building Vue framework libraries.
5
5
  - Hybrid ESM/CJS packages.
6
6
  - Transpiled with Babel.
7
7
  - Supports monorepo.
8
+ - Optional: build pageobjects and selectors.
8
9
 
9
10
  ## Configuration
10
11
 
@@ -82,6 +83,21 @@ To fix global module augmentations use:
82
83
 
83
84
  Use `--help` to see full description.
84
85
 
86
+ ### Optional: build pageobjects and selectors
87
+
88
+ ```diff
89
+ {
90
+ "scripts": {
91
+ "build": "fk-build-vue-lib",
92
+ + "build:selectors": "fk-build-selectors",
93
+ }
94
+ }
95
+ ```
96
+
97
+ If `src/selectors/index.ts` it will be built to `dist/${format}/selectors.${cjs,mjs}`.
98
+
99
+ If `src/cypress/index.ts` it will be built to `dist/${format}/cypress.${cjs,mjs}`.
100
+
85
101
  ### Dev-server
86
102
 
87
103
  ```json
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from "../dist/build-selectors.js";
4
+
5
+ const argv = process.argv.slice(2);
6
+
7
+ try {
8
+ await run(argv);
9
+ } catch (err) {
10
+ console.error(err);
11
+ process.exitCode = 1;
12
+ }
@@ -0,0 +1,102 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/build-selectors.ts
30
+ var build_selectors_exports = {};
31
+ __export(build_selectors_exports, {
32
+ getExternals: () => getExternals,
33
+ run: () => run
34
+ });
35
+ module.exports = __toCommonJS(build_selectors_exports);
36
+ var import_node_fs = require("node:fs");
37
+ var import_promises = __toESM(require("node:fs/promises"));
38
+ var import_posix = __toESM(require("node:path/posix"));
39
+ var esbuild = __toESM(require("esbuild"));
40
+ var extension = {
41
+ cjs: ".cjs",
42
+ esm: ".mjs"
43
+ };
44
+ async function build2(entrypoint, options) {
45
+ const { external, formats } = options;
46
+ if (!(0, import_node_fs.existsSync)(entrypoint)) {
47
+ return;
48
+ }
49
+ const basename = import_posix.default.basename(import_posix.default.dirname(entrypoint));
50
+ for (const format of formats) {
51
+ const result = await esbuild.build({
52
+ entryPoints: [entrypoint],
53
+ outfile: `dist/${format}/${basename}.${format}.js`,
54
+ bundle: true,
55
+ platform: "browser",
56
+ format,
57
+ target: "chrome119",
58
+ sourcemap: true,
59
+ external,
60
+ outExtension: {
61
+ ".js": extension[format]
62
+ },
63
+ logLevel: "info",
64
+ metafile: true
65
+ });
66
+ if (format === "esm") {
67
+ const output = await esbuild.analyzeMetafile(result.metafile);
68
+ console.log(output);
69
+ }
70
+ }
71
+ }
72
+ async function readJsonFile(filePath) {
73
+ const content = await import_promises.default.readFile(filePath, "utf8");
74
+ return JSON.parse(content);
75
+ }
76
+ function getExternals(pkg) {
77
+ const { peerDependencies = {}, externalDependencies = [] } = pkg;
78
+ const unique = /* @__PURE__ */ new Set([
79
+ ...Object.keys(peerDependencies),
80
+ ...externalDependencies
81
+ ]);
82
+ return Array.from(unique).toSorted((a, b) => a.localeCompare(b));
83
+ }
84
+ async function run(argv) {
85
+ const flags = new Set(argv.filter((it) => it.startsWith("--")));
86
+ if (flags.has("--help")) {
87
+ console.log("usage: fk-build-selectors [OPTIONS..]");
88
+ console.log(`
89
+ --help Show this help.
90
+ `);
91
+ }
92
+ const pkg = await readJsonFile("package.json");
93
+ const external = getExternals(pkg);
94
+ const formats = ["cjs", "esm"];
95
+ await build2("src/cypress/index.ts", { external, formats });
96
+ await build2("src/selectors/index.ts", { external, formats });
97
+ }
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ getExternals,
101
+ run
102
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forsakringskassan/vite-lib-config",
3
- "version": "4.6.9",
3
+ "version": "4.7.1",
4
4
  "description": "Försäkringskassan toolchain to build libraries with Vite",
5
5
  "keywords": [
6
6
  "vite"
@@ -33,7 +33,8 @@
33
33
  "types": "./dist/index.d.ts",
34
34
  "bin": {
35
35
  "fk-api-extractor": "bin/api-extractor.js",
36
- "fk-build-vue-lib": "bin/build-vue-lib.mjs"
36
+ "fk-build-vue-lib": "bin/build-vue-lib.mjs",
37
+ "fk-build-selectors": "bin/build-selectors.mjs"
37
38
  },
38
39
  "files": [
39
40
  "*.d.ts",
@@ -43,7 +44,8 @@
43
44
  ],
44
45
  "dependencies": {
45
46
  "@microsoft/api-extractor": "7.58.7",
46
- "@vue/babel-preset-app": "5.0.9"
47
+ "@vue/babel-preset-app": "5.0.9",
48
+ "esbuild": "^0.28.0"
47
49
  },
48
50
  "peerDependencies": {
49
51
  "@babel/core": "^7.22.0",