@grafana/plugin-types-bundler 0.3.0 → 0.3.1-canary.1688.14352150976.0

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/dist/args.js CHANGED
@@ -1,8 +1,24 @@
1
- import {
2
- DEFAULT_ARGS,
3
- parsedArgs
4
- } from "./chunk-3T7KI6U2.js";
5
- export {
6
- DEFAULT_ARGS,
7
- parsedArgs
1
+ import parseArgs from 'minimist';
2
+ import { join, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const args = process.argv.slice(2);
6
+ const __dirname = fileURLToPath(new URL(".", import.meta.url));
7
+ const parsedArgs = parseArgs(args, {
8
+ alias: {
9
+ entryPoint: "entry-point",
10
+ tsConfig: "ts-config",
11
+ outDir: "out-dir"
12
+ },
13
+ string: ["entryPoint", "tsConfig", "outDir"],
14
+ unknown: (arg) => {
15
+ console.error(`Unknown argument: ${arg}`);
16
+ process.exit(1);
17
+ }
18
+ });
19
+ const DEFAULT_ARGS = {
20
+ tsConfig: resolve(__dirname, "../tsconfig", "tsconfig.json"),
21
+ outDir: join(process.cwd(), "dist")
8
22
  };
23
+
24
+ export { DEFAULT_ARGS, parsedArgs };
package/dist/bin/run.js CHANGED
@@ -1,17 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- generateTypes
4
- } from "../chunk-SCBFTMD7.js";
5
- import {
6
- parsedArgs
7
- } from "../chunk-3T7KI6U2.js";
8
- import {
9
- debug
10
- } from "../chunk-DOK72DBQ.js";
2
+ import { existsSync } from 'fs';
3
+ import { parsedArgs } from '../args.js';
4
+ import { generateTypes } from '../bundleTypes.js';
5
+ import { debug } from '../debug.js';
11
6
 
12
- // src/bin/run.ts
13
- import { existsSync } from "fs";
14
- var { entryPoint, tsConfig, outDir } = parsedArgs;
7
+ let { entryPoint, tsConfig, outDir } = parsedArgs;
15
8
  if (entryPoint === void 0) {
16
9
  console.error("Please provide the path for the entry types file as an argument.");
17
10
  console.error('(E.g. "npx @grafana/plugin-types-bundler ./src/types/index.ts")');
@@ -21,7 +14,7 @@ if (!existsSync(entryPoint)) {
21
14
  console.error(`File not found: ${entryPoint}`);
22
15
  process.exit(1);
23
16
  }
24
- var startTime = Date.now().valueOf();
17
+ const startTime = Date.now().valueOf();
25
18
  try {
26
19
  console.log("\u26A1\uFE0F Starting to bundle types for plugin...");
27
20
  debug({ entryPoint, tsConfig, outDir });
@@ -30,5 +23,5 @@ try {
30
23
  console.error("Error while bundling types:", error);
31
24
  process.exit(1);
32
25
  }
33
- var endTime = Date.now().valueOf();
26
+ const endTime = Date.now().valueOf();
34
27
  console.log(`\u{1F4E6} Types bundled successfully (${endTime - startTime}ms)`);
@@ -1,8 +1,63 @@
1
- import {
2
- generateTypes
3
- } from "./chunk-SCBFTMD7.js";
4
- import "./chunk-3T7KI6U2.js";
5
- import "./chunk-DOK72DBQ.js";
6
- export {
7
- generateTypes
1
+ import { getImportsInfo } from '@grafana/levitate';
2
+ import { generateDtsBundle } from 'jackw-dts-bundle-gen-test';
3
+ import { mkdirSync, writeFileSync, existsSync } from 'node:fs';
4
+ import { join, extname } from 'node:path';
5
+ import { DEFAULT_ARGS } from './args.js';
6
+ import { debug } from './debug.js';
7
+
8
+ const generateTypes = (args) => {
9
+ const { entryPoint, tsConfig, outDir } = handleArgs(args);
10
+ const entryPoints = [
11
+ {
12
+ filePath: entryPoint,
13
+ libraries: {
14
+ inlinedLibraries: getImportedPackages(entryPoint)
15
+ }
16
+ }
17
+ ];
18
+ const options = {
19
+ preferredConfigPath: tsConfig
20
+ };
21
+ debug({ ...entryPoints[0], ...options });
22
+ const dts = generateDtsBundle(entryPoints, options);
23
+ const cleanedDts = cleanDTS(dts);
24
+ mkdirSync(outDir, { recursive: true });
25
+ writeFileSync(join(outDir, "index.d.ts"), cleanedDts);
8
26
  };
27
+ function getImportedPackages(entryPoint) {
28
+ const { imports } = getImportsInfo(entryPoint);
29
+ const npmPackages = imports.map((importInfo) => importInfo.packageName).filter((packageName) => isBareSpecifier(packageName));
30
+ return Array.from(new Set(npmPackages));
31
+ }
32
+ function cleanDTS(dtsContent) {
33
+ let dtsString = dtsContent.join("\n");
34
+ dtsString = dtsString.replace("export {};", "");
35
+ return dtsString.trim() + "\n";
36
+ }
37
+ function isBareSpecifier(packageName) {
38
+ const isRelative = packageName.startsWith("./") || packageName.startsWith("../") || packageName.startsWith("/");
39
+ const hasExtension = extname(packageName) !== "";
40
+ return !isRelative && !hasExtension;
41
+ }
42
+ function handleArgs(args) {
43
+ let { entryPoint, tsConfig, outDir } = args;
44
+ if (entryPoint === void 0) {
45
+ throw new Error(
46
+ 'Please provide the path for the entry types file as an argument. (E.g. "npx @grafana/plugin-types-bundler --entry-point ./src/types/index.ts")'
47
+ );
48
+ }
49
+ if (!existsSync(entryPoint)) {
50
+ throw new Error(`Entry point not found: ${entryPoint}`);
51
+ }
52
+ if (!Boolean(tsConfig)) {
53
+ debug("No tsconfig provided, using default tsconfig.json ('../tsconfig/tsconfig.json')");
54
+ tsConfig = DEFAULT_ARGS.tsConfig;
55
+ }
56
+ if (!Boolean(outDir)) {
57
+ debug("No outDir provided, using default dist ('./dist')");
58
+ outDir = DEFAULT_ARGS.outDir;
59
+ }
60
+ return { entryPoint, tsConfig, outDir };
61
+ }
62
+
63
+ export { generateTypes };
package/dist/debug.js CHANGED
@@ -1,6 +1,5 @@
1
- import {
2
- debug
3
- } from "./chunk-DOK72DBQ.js";
4
- export {
5
- debug
6
- };
1
+ import createDebug from 'debug';
2
+
3
+ const debug = createDebug("plugin-types-bundler");
4
+
5
+ export { debug };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/plugin-types-bundler",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-canary.1688.14352150976.0",
4
4
  "description": "Bundle grafana plugin typescript types for sharing with other plugins",
5
5
  "bin": "./dist/bin/run.js",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "test": "vitest --passWithNoTests",
20
- "build": "tsup",
21
- "dev": "tsup --watch ./src",
20
+ "build": "rollup -c ../../rollup.config.ts --configPlugin esbuild",
21
+ "dev": "npm run build -- -w",
22
22
  "lint": "eslint --cache ./src",
23
23
  "lint:fix": "npm run lint -- --fix",
24
24
  "typecheck": "tsc --noEmit"
@@ -55,5 +55,5 @@
55
55
  "jackw-dts-bundle-gen-test": "^9.5.1",
56
56
  "minimist": "^1.2.8"
57
57
  },
58
- "gitHead": "b622bcaa222af1bf67aa602eb2accecad44f1afc"
58
+ "gitHead": "93672b6574cdb1575a283eb3fbab0c2fd837d407"
59
59
  }
@@ -1,28 +0,0 @@
1
- // src/args.ts
2
- import parseArgs from "minimist";
3
- import { join, resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- var args = process.argv.slice(2);
6
- var __dirname = fileURLToPath(new URL(".", import.meta.url));
7
- var parsedArgs = parseArgs(args, {
8
- alias: {
9
- entryPoint: "entry-point",
10
- tsConfig: "ts-config",
11
- outDir: "out-dir"
12
- },
13
- string: ["entryPoint", "tsConfig", "outDir"],
14
- unknown: (arg) => {
15
- console.error(`Unknown argument: ${arg}`);
16
- process.exit(1);
17
- }
18
- });
19
- var DEFAULT_ARGS = {
20
- entryPoint: void 0,
21
- tsConfig: resolve(__dirname, "../tsconfig", "tsconfig.json"),
22
- outDir: join(process.cwd(), "dist")
23
- };
24
-
25
- export {
26
- parsedArgs,
27
- DEFAULT_ARGS
28
- };
@@ -1,7 +0,0 @@
1
- // src/debug.ts
2
- import createDebug from "debug";
3
- var debug = createDebug("plugin-types-bundler");
4
-
5
- export {
6
- debug
7
- };
@@ -1,70 +0,0 @@
1
- import {
2
- DEFAULT_ARGS
3
- } from "./chunk-3T7KI6U2.js";
4
- import {
5
- debug
6
- } from "./chunk-DOK72DBQ.js";
7
-
8
- // src/bundleTypes.ts
9
- import { getImportsInfo } from "@grafana/levitate";
10
- import { generateDtsBundle } from "jackw-dts-bundle-gen-test";
11
- import { mkdirSync, writeFileSync, existsSync } from "node:fs";
12
- import { extname, join } from "node:path";
13
- var generateTypes = (args) => {
14
- const { entryPoint, tsConfig, outDir } = handleArgs(args);
15
- const entryPoints = [
16
- {
17
- filePath: entryPoint,
18
- libraries: {
19
- inlinedLibraries: getImportedPackages(entryPoint)
20
- }
21
- }
22
- ];
23
- const options = {
24
- preferredConfigPath: tsConfig
25
- };
26
- debug({ ...entryPoints[0], ...options });
27
- const dts = generateDtsBundle(entryPoints, options);
28
- const cleanedDts = cleanDTS(dts);
29
- mkdirSync(outDir, { recursive: true });
30
- writeFileSync(join(outDir, "index.d.ts"), cleanedDts);
31
- };
32
- function getImportedPackages(entryPoint) {
33
- const { imports } = getImportsInfo(entryPoint);
34
- const npmPackages = imports.map((importInfo) => importInfo.packageName).filter((packageName) => isBareSpecifier(packageName));
35
- return Array.from(new Set(npmPackages));
36
- }
37
- function cleanDTS(dtsContent) {
38
- let dtsString = dtsContent.join("\n");
39
- dtsString = dtsString.replace("export {};", "");
40
- return dtsString.trim() + "\n";
41
- }
42
- function isBareSpecifier(packageName) {
43
- const isRelative = packageName.startsWith("./") || packageName.startsWith("../") || packageName.startsWith("/");
44
- const hasExtension = extname(packageName) !== "";
45
- return !isRelative && !hasExtension;
46
- }
47
- function handleArgs(args) {
48
- let { entryPoint, tsConfig, outDir } = args;
49
- if (entryPoint === void 0) {
50
- throw new Error(
51
- 'Please provide the path for the entry types file as an argument. (E.g. "npx @grafana/plugin-types-bundler --entry-point ./src/types/index.ts")'
52
- );
53
- }
54
- if (!existsSync(entryPoint)) {
55
- throw new Error(`Entry point not found: ${entryPoint}`);
56
- }
57
- if (!Boolean(tsConfig)) {
58
- debug("No tsconfig provided, using default tsconfig.json ('../tsconfig/tsconfig.json')");
59
- tsConfig = DEFAULT_ARGS.tsConfig;
60
- }
61
- if (!Boolean(outDir)) {
62
- debug("No outDir provided, using default dist ('./dist')");
63
- outDir = DEFAULT_ARGS.outDir;
64
- }
65
- return { entryPoint, tsConfig, outDir };
66
- }
67
-
68
- export {
69
- generateTypes
70
- };