@grafana/plugin-types-bundler 0.0.1-canary.1092.a678194.0 → 0.0.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/index.js +1 -0
- package/package.json +6 -27
- package/dist/bin/run.js +0 -25
- package/dist/bundleTypes.js +0 -41
- package/dist/utils.js +0 -20
- package/src/bin/run.ts +0 -31
- package/src/bundleTypes.ts +0 -49
- package/src/utils.ts +0 -28
- package/tsconfig.json +0 -9
package/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
console.log('@grafana/plugin-types-bundler');
|
package/package.json
CHANGED
@@ -1,31 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@grafana/plugin-types-bundler",
|
3
|
-
"version": "0.0.1
|
3
|
+
"version": "0.0.1",
|
4
4
|
"description": "Bundle grafana plugin typescript types for sharing with other plugins",
|
5
|
-
"
|
6
|
-
"type": "module",
|
7
|
-
"exports": {
|
8
|
-
"node": {
|
9
|
-
"import": "./dist/bundleTypes.js"
|
10
|
-
},
|
11
|
-
"default": "./dist/bundleTypes.js"
|
12
|
-
},
|
5
|
+
"main": "index.js",
|
13
6
|
"scripts": {
|
14
|
-
"test": "
|
15
|
-
"build": "tsc --project tsconfig.json && chmod +x ./dist/bin/run.js",
|
16
|
-
"dev": "tsc --project tsconfig.json --watch",
|
17
|
-
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./src",
|
18
|
-
"lint:fix": "npm run lint -- --fix",
|
19
|
-
"typecheck": "tsc --noEmit"
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
20
8
|
},
|
21
9
|
"publishConfig": {
|
22
10
|
"registry": "https://registry.npmjs.org/",
|
23
|
-
"access": "public"
|
24
|
-
"provenance": true
|
11
|
+
"access": "public"
|
25
12
|
},
|
26
13
|
"repository": {
|
27
14
|
"directory": "packages/plugin-types-bundler",
|
28
|
-
"url": "https://github.com/grafana/plugin-tools"
|
15
|
+
"url": "git+https://github.com/grafana/plugin-tools.git"
|
29
16
|
},
|
30
17
|
"keywords": [
|
31
18
|
"grafana",
|
@@ -41,13 +28,5 @@
|
|
41
28
|
},
|
42
29
|
"engines": {
|
43
30
|
"node": ">=18.8.0"
|
44
|
-
}
|
45
|
-
"dependencies": {
|
46
|
-
"@grafana/levitate": "^0.14.0",
|
47
|
-
"@types/minimist": "^1.2.2",
|
48
|
-
"@types/node": "20.10.1",
|
49
|
-
"jackw-dts-bundle-gen-test": "^9.5.1",
|
50
|
-
"minimist": "^1.2.8"
|
51
|
-
},
|
52
|
-
"gitHead": "a678194b8772ec72d3233b8ecf304c9153f333eb"
|
31
|
+
}
|
53
32
|
}
|
package/dist/bin/run.js
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import { existsSync } from 'fs';
|
3
|
-
import { generateTypes } from '../bundleTypes.js';
|
4
|
-
import { parsedArgs } from '../utils.js';
|
5
|
-
const { entryPoint, tsConfig, outDir } = parsedArgs;
|
6
|
-
if (entryPoint === undefined) {
|
7
|
-
console.error('Please provide the path for the entry types file as an argument.');
|
8
|
-
console.error('(E.g. "npx @grafana/plugin-types-bundler ./src/types/index.ts")');
|
9
|
-
process.exit(1);
|
10
|
-
}
|
11
|
-
if (!existsSync(entryPoint)) {
|
12
|
-
console.error(`File not found: ${entryPoint}`);
|
13
|
-
process.exit(1);
|
14
|
-
}
|
15
|
-
const startTime = Date.now().valueOf();
|
16
|
-
try {
|
17
|
-
console.log('⚡️ Starting to bundle types for plugin...');
|
18
|
-
generateTypes({ entryPoint, tsConfig, outDir });
|
19
|
-
}
|
20
|
-
catch (error) {
|
21
|
-
console.error('Error while bundling types:', error);
|
22
|
-
process.exit(1);
|
23
|
-
}
|
24
|
-
const endTime = Date.now().valueOf();
|
25
|
-
console.log(`📦 Types bundled successfully (${endTime - startTime}ms)`);
|
package/dist/bundleTypes.js
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import { getImportsInfo } from '@grafana/levitate';
|
2
|
-
import { generateDtsBundle } from 'jackw-dts-bundle-gen-test';
|
3
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
4
|
-
import { extname, join } from 'node:path';
|
5
|
-
export const generateTypes = ({ entryPoint, tsConfig, outDir }) => {
|
6
|
-
if (!entryPoint) {
|
7
|
-
throw new Error('Please provide the path for the entry types file as an argument.');
|
8
|
-
}
|
9
|
-
const entryPoints = [
|
10
|
-
{
|
11
|
-
filePath: entryPoint,
|
12
|
-
libraries: {
|
13
|
-
inlinedLibraries: getImportedPackages(entryPoint),
|
14
|
-
},
|
15
|
-
},
|
16
|
-
];
|
17
|
-
const options = {
|
18
|
-
preferredConfigPath: tsConfig,
|
19
|
-
};
|
20
|
-
const dts = generateDtsBundle(entryPoints, options);
|
21
|
-
const cleanedDts = cleanDTS(dts);
|
22
|
-
mkdirSync(outDir, { recursive: true });
|
23
|
-
writeFileSync(join(outDir, 'index.d.ts'), cleanedDts);
|
24
|
-
};
|
25
|
-
function getImportedPackages(entryPoint) {
|
26
|
-
const { imports } = getImportsInfo(entryPoint);
|
27
|
-
const npmPackages = imports
|
28
|
-
.map((importInfo) => importInfo.packageName)
|
29
|
-
.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
|
-
}
|
package/dist/utils.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import parseArgs from 'minimist';
|
2
|
-
import { join } from 'node:path';
|
3
|
-
const args = process.argv.slice(2);
|
4
|
-
export const parsedArgs = parseArgs(args, {
|
5
|
-
alias: {
|
6
|
-
entryPoint: 'entry-point',
|
7
|
-
tsConfig: 'ts-config',
|
8
|
-
outDir: 'out-dir',
|
9
|
-
},
|
10
|
-
string: ['entryPoint', 'tsConfig', 'outDir'],
|
11
|
-
unknown: (arg) => {
|
12
|
-
console.error(`Unknown argument: ${arg}`);
|
13
|
-
process.exit(1);
|
14
|
-
},
|
15
|
-
default: {
|
16
|
-
entryPoint: undefined,
|
17
|
-
tsConfig: join(process.cwd(), 'tsconfig.json'),
|
18
|
-
outDir: join(process.cwd(), 'dist'),
|
19
|
-
},
|
20
|
-
});
|
package/src/bin/run.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import { existsSync } from 'fs';
|
3
|
-
import { generateTypes } from '../bundleTypes.js';
|
4
|
-
import { parsedArgs } from '../utils.js';
|
5
|
-
|
6
|
-
const { entryPoint, tsConfig, outDir } = parsedArgs;
|
7
|
-
|
8
|
-
// Check if the first argument is present
|
9
|
-
if (entryPoint === undefined) {
|
10
|
-
console.error('Please provide the path for the entry types file as an argument.');
|
11
|
-
console.error('(E.g. "npx @grafana/plugin-types-bundler ./src/types/index.ts")');
|
12
|
-
process.exit(1);
|
13
|
-
}
|
14
|
-
|
15
|
-
// Check if the file exists
|
16
|
-
if (!existsSync(entryPoint)) {
|
17
|
-
console.error(`File not found: ${entryPoint}`);
|
18
|
-
process.exit(1);
|
19
|
-
}
|
20
|
-
|
21
|
-
const startTime = Date.now().valueOf();
|
22
|
-
try {
|
23
|
-
console.log('⚡️ Starting to bundle types for plugin...');
|
24
|
-
generateTypes({ entryPoint, tsConfig, outDir });
|
25
|
-
} catch (error) {
|
26
|
-
console.error('Error while bundling types:', error);
|
27
|
-
process.exit(1);
|
28
|
-
}
|
29
|
-
|
30
|
-
const endTime = Date.now().valueOf();
|
31
|
-
console.log(`📦 Types bundled successfully (${endTime - startTime}ms)`);
|
package/src/bundleTypes.ts
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
import { getImportsInfo } from '@grafana/levitate';
|
2
|
-
import { EntryPointConfig, generateDtsBundle } from 'jackw-dts-bundle-gen-test';
|
3
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
4
|
-
import { extname, join } from 'node:path';
|
5
|
-
import type { ParsedArgs } from './utils.js';
|
6
|
-
|
7
|
-
export const generateTypes = ({ entryPoint, tsConfig, outDir }: ParsedArgs) => {
|
8
|
-
if (!entryPoint) {
|
9
|
-
throw new Error('Please provide the path for the entry types file as an argument.');
|
10
|
-
}
|
11
|
-
|
12
|
-
const entryPoints: EntryPointConfig[] = [
|
13
|
-
{
|
14
|
-
filePath: entryPoint,
|
15
|
-
libraries: {
|
16
|
-
inlinedLibraries: getImportedPackages(entryPoint),
|
17
|
-
},
|
18
|
-
},
|
19
|
-
];
|
20
|
-
const options = {
|
21
|
-
preferredConfigPath: tsConfig,
|
22
|
-
};
|
23
|
-
const dts = generateDtsBundle(entryPoints, options);
|
24
|
-
const cleanedDts = cleanDTS(dts);
|
25
|
-
|
26
|
-
mkdirSync(outDir, { recursive: true });
|
27
|
-
writeFileSync(join(outDir, 'index.d.ts'), cleanedDts);
|
28
|
-
};
|
29
|
-
|
30
|
-
function getImportedPackages(entryPoint: string) {
|
31
|
-
const { imports } = getImportsInfo(entryPoint);
|
32
|
-
const npmPackages = imports
|
33
|
-
.map((importInfo) => importInfo.packageName)
|
34
|
-
.filter((packageName) => isBareSpecifier(packageName));
|
35
|
-
// Remove duplicates
|
36
|
-
return Array.from(new Set(npmPackages));
|
37
|
-
}
|
38
|
-
|
39
|
-
function cleanDTS(dtsContent: string[]) {
|
40
|
-
let dtsString = dtsContent.join('\n');
|
41
|
-
dtsString = dtsString.replace('export {};', '');
|
42
|
-
return dtsString.trim() + '\n';
|
43
|
-
}
|
44
|
-
|
45
|
-
function isBareSpecifier(packageName: string) {
|
46
|
-
const isRelative = packageName.startsWith('./') || packageName.startsWith('../') || packageName.startsWith('/');
|
47
|
-
const hasExtension = extname(packageName) !== '';
|
48
|
-
return !isRelative && !hasExtension;
|
49
|
-
}
|
package/src/utils.ts
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
import parseArgs from 'minimist';
|
2
|
-
import { join } from 'node:path';
|
3
|
-
|
4
|
-
const args = process.argv.slice(2);
|
5
|
-
|
6
|
-
export type ParsedArgs = {
|
7
|
-
entryPoint?: string;
|
8
|
-
tsConfig: string;
|
9
|
-
outDir: string;
|
10
|
-
};
|
11
|
-
|
12
|
-
export const parsedArgs = parseArgs<ParsedArgs>(args, {
|
13
|
-
alias: {
|
14
|
-
entryPoint: 'entry-point',
|
15
|
-
tsConfig: 'ts-config',
|
16
|
-
outDir: 'out-dir',
|
17
|
-
},
|
18
|
-
string: ['entryPoint', 'tsConfig', 'outDir'],
|
19
|
-
unknown: (arg) => {
|
20
|
-
console.error(`Unknown argument: ${arg}`);
|
21
|
-
process.exit(1);
|
22
|
-
},
|
23
|
-
default: {
|
24
|
-
entryPoint: undefined,
|
25
|
-
tsConfig: join(process.cwd(), 'tsconfig.json'),
|
26
|
-
outDir: join(process.cwd(), 'dist'),
|
27
|
-
},
|
28
|
-
});
|