esbuild-ignore-with-comments-plugin 0.1.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 ADDED
@@ -0,0 +1,3 @@
1
+ # ESBuild Ignore with Comments Plugin
2
+
3
+ Allows inserting comments into TypeScript source files. ESBuild will ignore these files during build.
@@ -0,0 +1,9 @@
1
+ import { Plugin } from 'esbuild';
2
+ export interface IgnoreWithCommentsPluginOptions {
3
+ ignore: string[];
4
+ }
5
+ export declare function mustIgnore(comments: string[], ignore: string[] | undefined): boolean;
6
+ export declare function findComments(text: string): string[];
7
+ declare const pluginFactory: (opts?: IgnoreWithCommentsPluginOptions) => Plugin;
8
+ export default pluginFactory;
9
+ //# sourceMappingURL=esbuildIgnoreWithCommentsPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuildIgnoreWithCommentsPlugin.d.ts","sourceRoot":"","sources":["../../src/esbuildIgnoreWithCommentsPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,MAAM,EAAe,MAAM,SAAS,CAAC;AAIxE,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAsCD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,GAC3B,OAAO,CAaT;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAanD;AAED,QAAA,MAAM,aAAa,UAAW,+BAA+B,KAAG,MAE/D,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findComments = exports.mustIgnore = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const ignorePlugin = (opts) => {
9
+ return {
10
+ name: 'ignore-with-comments-plugin',
11
+ setup: (build) => {
12
+ // build.onResolve({ filter: /.*/, namespace: 'ignore' }, (args) => {
13
+ // return {
14
+ // path: args.path,
15
+ // namespace: 'ignore',
16
+ // };
17
+ // });
18
+ build.onLoad({
19
+ filter: /\.(ts|tsx)$/,
20
+ }, async (args) => {
21
+ const text = await fs_1.default.promises.readFile(args.path, 'utf8');
22
+ const res = findComments(text);
23
+ if (mustIgnore(res, opts === null || opts === void 0 ? void 0 : opts.ignore)) {
24
+ return {
25
+ contents: 'const dummy = {}; export default dummy;',
26
+ loader: 'ts',
27
+ };
28
+ }
29
+ const type = args.path.endsWith('.ts') ? 'ts' : 'tsx';
30
+ return {
31
+ contents: text,
32
+ loader: type,
33
+ };
34
+ });
35
+ },
36
+ };
37
+ };
38
+ function mustIgnore(comments, ignore) {
39
+ if (comments.length === 0) {
40
+ return false;
41
+ }
42
+ if (!ignore) {
43
+ return true;
44
+ }
45
+ const reducer = (prev, curr) => {
46
+ return (prev && comments.find((el) => el === curr || el === '') !== undefined);
47
+ };
48
+ return ignore.reduce(reducer, true);
49
+ }
50
+ exports.mustIgnore = mustIgnore;
51
+ function findComments(text) {
52
+ const commentRegex = /^\s*\/\* esbuild-ignore ([^\s\*]*)/gm;
53
+ const res = [];
54
+ let matches;
55
+ do {
56
+ matches = commentRegex.exec(text);
57
+ if (matches && matches.length > 1) {
58
+ res.push(matches[1]);
59
+ }
60
+ } while (matches !== null);
61
+ return res;
62
+ }
63
+ exports.findComments = findComments;
64
+ const pluginFactory = (opts) => {
65
+ return ignorePlugin(opts);
66
+ };
67
+ exports.default = pluginFactory;
68
+ //# sourceMappingURL=esbuildIgnoreWithCommentsPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuildIgnoreWithCommentsPlugin.js","sourceRoot":"","sources":["../../src/esbuildIgnoreWithCommentsPlugin.ts"],"names":[],"mappings":";;;;;;AAEA,4CAAoB;AAMpB,MAA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AC,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,SAAS,CACtE,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAhBD,gCAgBC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,MAAM,YAAY,GAAG,sCAAsC,CAAC;IAC5D,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,OAA+B,CAAC;IACpC,GAAG;QACD,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACjC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;SACtB;KACF,QAAQ,OAAO,KAAK,IAAI,EAAE;IAE3B,OAAO,GAAG,CAAC;AACb,CAAC;AAbD,oCAaC;AAED,MAAM,aAAa,GAAG,CAAC,IAAsC,EAAU,EAAE;IACvE,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "esbuild-ignore-with-comments-plugin",
3
+ "version": "0.1.1",
4
+ "description": "esbuild Plugin for ignoring files with specific comments in them",
5
+ "keywords": [
6
+ "node",
7
+ "javascript",
8
+ "esbuild"
9
+ ],
10
+ "homepage": "",
11
+ "bugs": {
12
+ "url": "https://github.com/goldstack/goldstack/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/goldstack/goldstack.git"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Max Rohde",
20
+ "sideEffects": false,
21
+ "main": "dist/src/esbuildIgnoreWithCommentsPlugin.js",
22
+ "scripts": {
23
+ "build": "yarn clean && yarn compile",
24
+ "build:watch": "yarn clean && yarn compile-watch",
25
+ "clean": "rimraf ./dist",
26
+ "compile": "tsc -p tsconfig.json",
27
+ "compile-watch": "tsc -p tsconfig.json --watch",
28
+ "compile-watch:light": "nodemon --watch ./src/ -e '*' --exec 'yarn compile'",
29
+ "coverage": "jest --collect-coverage --passWithNoTests --config=./jest.config.js --runInBand",
30
+ "prepublishOnly": "yarn run build",
31
+ "publish": "utils-git changed --exec \"yarn npm publish $@\"",
32
+ "test-ci": "jest --passWithNoTests --config=./jest.config.js --runInBand",
33
+ "version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\""
34
+ },
35
+ "devDependencies": {
36
+ "@goldstack/utils-git": "0.1.37",
37
+ "@types/jest": "^28.1.8",
38
+ "@types/node": "^18.7.13",
39
+ "esbuild": "^0.15.5",
40
+ "jest": "^28.1.0",
41
+ "rimraf": "^3.0.2",
42
+ "ts-jest": "^28.0.2",
43
+ "typescript": "^4.7.4"
44
+ },
45
+ "publishConfig": {
46
+ "main": "dist/src/esbuildIgnoreWithCommentsPlugin.js"
47
+ }
48
+ }