rollup-plugin-keywords 1.0.1 → 1.0.2

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/cli.js CHANGED
@@ -1,8 +1,123 @@
1
- // src/cli.ts
2
- import {
3
- collectKeywordsAndGenerateTypes,
4
- createPrefixedLogger
5
- } from "minifiable-keywords";
1
+ // ../minifiable-keywords/dist/index.js
2
+ import { mkdir, readFile, writeFile } from "fs/promises";
3
+ import path from "path";
4
+ import { parse } from "@babel/parser";
5
+ import _traverse from "@babel/traverse";
6
+ import { globby } from "globby";
7
+ var VIRTUAL_MODULE_ID = "virtual:keywords";
8
+ var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
9
+ var createPrefixedLogger = (logger, pluginName, usePrefix = true) => {
10
+ const prefix = usePrefix ? `[${pluginName}] ` : "";
11
+ const prefixed = (message) => `${prefix}${message}`;
12
+ return {
13
+ pluginName,
14
+ info: (message) => logger.info(prefixed(message)),
15
+ warn: (message) => logger.warn(prefixed(message)),
16
+ error: (message) => logger.error(prefixed(message))
17
+ };
18
+ };
19
+ var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
20
+ var extractKeywords = (code) => {
21
+ const keywords = /* @__PURE__ */ new Set();
22
+ let ast;
23
+ try {
24
+ ast = parse(code, {
25
+ sourceType: "module",
26
+ plugins: ["typescript", "jsx"],
27
+ errorRecovery: true
28
+ });
29
+ } catch (e) {
30
+ return keywords;
31
+ }
32
+ const keywordNamespaces = /* @__PURE__ */ new Set();
33
+ traverse(ast, {
34
+ enter(nodePath) {
35
+ const node = nodePath.node;
36
+ if (node.type === "ImportDeclaration" && node.source.value === VIRTUAL_MODULE_ID) {
37
+ for (const specifier of node.specifiers) {
38
+ if (specifier.type === "ImportNamespaceSpecifier") {
39
+ keywordNamespaces.add(specifier.local.name);
40
+ }
41
+ if (specifier.type === "ImportDefaultSpecifier") {
42
+ keywords.add("default");
43
+ }
44
+ if (specifier.type === "ImportSpecifier") {
45
+ if (specifier.imported.type === "Identifier") {
46
+ keywords.add(specifier.imported.name);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ });
53
+ if (keywordNamespaces.size === 0) {
54
+ return keywords;
55
+ }
56
+ traverse(ast, {
57
+ enter(nodePath) {
58
+ const node = nodePath.node;
59
+ if (node.type === "MemberExpression" && !node.computed && // Exclude computed properties like K['xyz']
60
+ node.object.type === "Identifier" && keywordNamespaces.has(node.object.name) && node.property.type === "Identifier") {
61
+ keywords.add(node.property.name);
62
+ }
63
+ if (node.type === "TSQualifiedName" && node.left.type === "Identifier" && keywordNamespaces.has(node.left.name) && node.right.type === "Identifier") {
64
+ keywords.add(node.right.name);
65
+ }
66
+ }
67
+ });
68
+ return keywords;
69
+ };
70
+ var keywordConstPrefix = "_";
71
+ var createExportDeclaration = (keywords) => {
72
+ const aliases = [...keywords].map(
73
+ (key) => ` ${keywordConstPrefix}${key} as ${key},`
74
+ );
75
+ return [`export {`, ...aliases, `};`];
76
+ };
77
+ var generateTypesFile = async (collectedKeywords, root, dirname = ".keywords", filename = "types.d.ts") => {
78
+ const keywordDeclarations = [...collectedKeywords].map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`).map((line) => ` ${line}`).join("\n");
79
+ const exportDeclaration = createExportDeclaration(collectedKeywords).map((line) => ` ${line}`).join("\n");
80
+ const content = `declare module '${VIRTUAL_MODULE_ID}' {
81
+ ${keywordDeclarations}
82
+ ${exportDeclaration}
83
+ }`;
84
+ const pluginRoot = path.join(root, dirname);
85
+ await mkdir(pluginRoot, { recursive: true });
86
+ await writeFile(path.join(pluginRoot, filename), `${content.trim()}
87
+ `);
88
+ };
89
+ var collectKeywordsFromFiles = async (root, logger, ignoredDirs = []) => {
90
+ const collectedKeywords = /* @__PURE__ */ new Set();
91
+ logger.info("Scanning project files for keywords...");
92
+ const files = await globby("**/*.{js,ts,jsx,tsx}", {
93
+ cwd: root,
94
+ absolute: true,
95
+ ignore: ["**/node_modules/**", ...ignoredDirs.map((dir) => `${dir}/**`)],
96
+ gitignore: true
97
+ });
98
+ await Promise.all(
99
+ files.map(async (file) => {
100
+ const code = await readFile(file, "utf-8");
101
+ const keywords = extractKeywords(code);
102
+ for (const key of keywords) {
103
+ collectedKeywords.add(key);
104
+ }
105
+ })
106
+ );
107
+ logger.info(
108
+ `Scan complete. Found ${collectedKeywords.size} unique keywords.`
109
+ );
110
+ return collectedKeywords;
111
+ };
112
+ var collectKeywordsAndGenerateTypes = async (root, logger, ignoredDirs) => {
113
+ const collectedKeywords = await collectKeywordsFromFiles(
114
+ root,
115
+ logger,
116
+ ignoredDirs
117
+ );
118
+ await generateTypesFile(collectedKeywords, root);
119
+ return collectedKeywords;
120
+ };
6
121
 
7
122
  // src/shared.ts
8
123
  var PLUGIN_NAME = "rollup-plugin-keywords";
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/shared.ts"],"sourcesContent":["import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n} from 'minifiable-keywords';\nimport { PLUGIN_NAME } from './shared';\n\nconst main = async () => {\n const root = process.cwd();\n const logger = createPrefixedLogger(console, PLUGIN_NAME);\n await collectKeywordsAndGenerateTypes(root, logger);\n};\n\nawait main();\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACHA,IAAM,cAAc;;;ADM3B,IAAM,OAAO,YAAY;AACvB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,qBAAqB,SAAS,WAAW;AACxD,QAAM,gCAAgC,MAAM,MAAM;AACpD;AAEA,MAAM,KAAK;","names":[]}
1
+ {"version":3,"sources":["../../minifiable-keywords/src/index.ts","../src/shared.ts","../src/cli.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { parse } from '@babel/parser';\nimport _traverse, { type Node } from '@babel/traverse';\nimport { globby } from 'globby';\n\nexport const VIRTUAL_MODULE_ID = 'virtual:keywords';\nexport const RESOLVED_VIRTUAL_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`;\n\nexport interface Logger {\n info: (message: string) => void;\n warn: (message: string) => void;\n error: (message: string) => void;\n}\n\nexport interface PrefixedLogger extends Logger {\n pluginName: string;\n}\n\nexport const createPrefixedLogger = (\n logger: Logger,\n pluginName: string,\n usePrefix: boolean = true,\n): PrefixedLogger => {\n const prefix = usePrefix ? `[${pluginName}] ` : '';\n const prefixed = (message: string) => `${prefix}${message}`;\n return {\n pluginName,\n info: (message: string) => logger.info(prefixed(message)),\n warn: (message: string) => logger.warn(prefixed(message)),\n error: (message: string) => logger.error(prefixed(message)),\n };\n};\n\n// ref: https://github.com/babel/babel/discussions/13093\nconst traverse =\n typeof _traverse === 'function'\n ? _traverse\n : ((_traverse as any).default as typeof _traverse);\n\nexport const extractKeywords = (code: string): Set<string> => {\n const keywords = new Set<string>();\n\n let ast: Node;\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n });\n } catch (e) {\n return keywords;\n }\n\n const keywordNamespaces = new Set<string>();\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'ImportDeclaration' &&\n node.source.value === VIRTUAL_MODULE_ID\n ) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportNamespaceSpecifier') {\n keywordNamespaces.add(specifier.local.name);\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n keywords.add('default');\n }\n\n if (specifier.type === 'ImportSpecifier') {\n if (specifier.imported.type === 'Identifier') {\n keywords.add(specifier.imported.name);\n }\n }\n }\n }\n },\n });\n\n if (keywordNamespaces.size === 0) {\n return keywords;\n }\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'MemberExpression' &&\n !node.computed && // Exclude computed properties like K['xyz']\n node.object.type === 'Identifier' &&\n keywordNamespaces.has(node.object.name) &&\n node.property.type === 'Identifier'\n ) {\n keywords.add(node.property.name);\n }\n\n if (\n node.type === 'TSQualifiedName' &&\n node.left.type === 'Identifier' &&\n keywordNamespaces.has(node.left.name) &&\n node.right.type === 'Identifier'\n ) {\n keywords.add(node.right.name);\n }\n },\n });\n\n return keywords;\n};\n\nconst keywordConstPrefix = '_';\nconst createExportDeclaration = (keywords: Set<string>): string[] => {\n const aliases = [...keywords].map(\n (key) => ` ${keywordConstPrefix}${key} as ${key},`,\n );\n return [`export {`, ...aliases, `};`];\n};\n\nexport const generateTypesFile = async (\n collectedKeywords: Set<string>,\n root: string,\n dirname: string = '.keywords',\n filename: string = 'types.d.ts',\n): Promise<void> => {\n const keywordDeclarations = [...collectedKeywords]\n .map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`)\n .map((line) => ` ${line}`)\n .join('\\n');\n const exportDeclaration = createExportDeclaration(collectedKeywords)\n .map((line) => ` ${line}`)\n .join('\\n');\n const content = `declare module '${VIRTUAL_MODULE_ID}' {\\n${keywordDeclarations}\\n${exportDeclaration}\\n}`;\n const pluginRoot = path.join(root, dirname);\n await mkdir(pluginRoot, { recursive: true });\n await writeFile(path.join(pluginRoot, filename), `${content.trim()}\\n`);\n};\n\nexport const collectKeywordsFromFiles = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs: string[] = [],\n): Promise<Set<string>> => {\n const collectedKeywords = new Set<string>();\n\n logger.info('Scanning project files for keywords...');\n\n const files = await globby('**/*.{js,ts,jsx,tsx}', {\n cwd: root,\n absolute: true,\n ignore: ['**/node_modules/**', ...ignoredDirs.map((dir) => `${dir}/**`)],\n gitignore: true,\n });\n\n await Promise.all(\n files.map(async (file) => {\n const code = await readFile(file, 'utf-8');\n const keywords = extractKeywords(code);\n for (const key of keywords) {\n collectedKeywords.add(key);\n }\n }),\n );\n\n logger.info(\n `Scan complete. Found ${collectedKeywords.size} unique keywords.`,\n );\n\n return collectedKeywords;\n};\n\nexport const collectKeywordsAndGenerateTypes = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs?: string[],\n): Promise<Set<string>> => {\n const collectedKeywords = await collectKeywordsFromFiles(\n root,\n logger,\n ignoredDirs,\n );\n await generateTypesFile(collectedKeywords, root);\n return collectedKeywords;\n};\n\nexport const generateModuleCode = (\n collectedKeywords: Set<string>,\n isDev: boolean,\n): string => {\n const symbolConstructorName = '__SYMBOL__';\n const symbolDeclaration = `const ${symbolConstructorName} = Symbol;`;\n const keywordDeclarations = [...collectedKeywords]\n .map(\n (key) =>\n `const ${keywordConstPrefix}${key} = /* @__PURE__ */ ${symbolConstructorName}(${isDev ? `'${key}'` : ''});`,\n )\n .join('\\n');\n const exportDeclaration =\n createExportDeclaration(collectedKeywords).join('\\n');\n return `${symbolDeclaration}\\n${keywordDeclarations}\\n${exportDeclaration}\\n`;\n};\n\nexport const splitQuery = (id: string) => id.split('?');\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n","import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n} from 'minifiable-keywords';\nimport { PLUGIN_NAME } from './shared';\n\nconst main = async () => {\n const root = process.cwd();\n const logger = createPrefixedLogger(console, PLUGIN_NAME);\n await collectKeywordsAndGenerateTypes(root, logger);\n};\n\nawait main();\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,OAAO,eAA8B;AACrC,SAAS,cAAc;AAEhB,IAAM,oBAAoB;AAC1B,IAAM,6BAA6B,KAAK,iBAAiB;AAYzD,IAAM,uBAAuB,CAClC,QACA,YACA,YAAqB,SACF;AACnB,QAAM,SAAS,YAAY,IAAI,UAAU,OAAO;AAChD,QAAM,WAAW,CAAC,YAAoB,GAAG,MAAM,GAAG,OAAO;AACzD,SAAO;IACL;IACA,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,OAAO,CAAC;IACxD,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,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B,IAAI;AACrC,iBAAW,OAAO,UAAU;AAC1B,0BAAkB,IAAI,GAAG;MAC3B;IACF,CAAC;EACH;AAEA,SAAO;IACL,wBAAwB,kBAAkB,IAAI;EAChD;AAEA,SAAO;AACT;AAEO,IAAM,kCAAkC,OAC7C,MACA,QACA,gBACyB;AACzB,QAAM,oBAAoB,MAAM;IAC9B;IACA;IACA;EACF;AACA,QAAM,kBAAkB,mBAAmB,IAAI;AAC/C,SAAO;AACT;;;AC3LO,IAAM,cAAc;;;ACM3B,IAAM,OAAO,YAAY;AACvB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,qBAAqB,SAAS,WAAW;AACxD,QAAM,gCAAgC,MAAM,MAAM;AACpD;AAEA,MAAM,KAAK;","names":[]}
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -24,7 +34,140 @@ __export(index_exports, {
24
34
  keywordsPlugin: () => keywordsPlugin
25
35
  });
26
36
  module.exports = __toCommonJS(index_exports);
27
- var import_minifiable_keywords = require("minifiable-keywords");
37
+
38
+ // ../minifiable-keywords/dist/index.js
39
+ var import_promises = require("fs/promises");
40
+ var import_path = __toESM(require("path"), 1);
41
+ var import_parser = require("@babel/parser");
42
+ var import_traverse = __toESM(require("@babel/traverse"), 1);
43
+ var import_globby = require("globby");
44
+ var VIRTUAL_MODULE_ID = "virtual:keywords";
45
+ var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
46
+ var createPrefixedLogger = (logger, pluginName, usePrefix = true) => {
47
+ const prefix = usePrefix ? `[${pluginName}] ` : "";
48
+ const prefixed = (message) => `${prefix}${message}`;
49
+ return {
50
+ pluginName,
51
+ info: (message) => logger.info(prefixed(message)),
52
+ warn: (message) => logger.warn(prefixed(message)),
53
+ error: (message) => logger.error(prefixed(message))
54
+ };
55
+ };
56
+ var traverse = typeof import_traverse.default === "function" ? import_traverse.default : import_traverse.default.default;
57
+ var extractKeywords = (code) => {
58
+ const keywords = /* @__PURE__ */ new Set();
59
+ let ast;
60
+ try {
61
+ ast = (0, import_parser.parse)(code, {
62
+ sourceType: "module",
63
+ plugins: ["typescript", "jsx"],
64
+ errorRecovery: true
65
+ });
66
+ } catch (e) {
67
+ return keywords;
68
+ }
69
+ const keywordNamespaces = /* @__PURE__ */ new Set();
70
+ traverse(ast, {
71
+ enter(nodePath) {
72
+ const node = nodePath.node;
73
+ if (node.type === "ImportDeclaration" && node.source.value === VIRTUAL_MODULE_ID) {
74
+ for (const specifier of node.specifiers) {
75
+ if (specifier.type === "ImportNamespaceSpecifier") {
76
+ keywordNamespaces.add(specifier.local.name);
77
+ }
78
+ if (specifier.type === "ImportDefaultSpecifier") {
79
+ keywords.add("default");
80
+ }
81
+ if (specifier.type === "ImportSpecifier") {
82
+ if (specifier.imported.type === "Identifier") {
83
+ keywords.add(specifier.imported.name);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ });
90
+ if (keywordNamespaces.size === 0) {
91
+ return keywords;
92
+ }
93
+ traverse(ast, {
94
+ enter(nodePath) {
95
+ const node = nodePath.node;
96
+ if (node.type === "MemberExpression" && !node.computed && // Exclude computed properties like K['xyz']
97
+ node.object.type === "Identifier" && keywordNamespaces.has(node.object.name) && node.property.type === "Identifier") {
98
+ keywords.add(node.property.name);
99
+ }
100
+ if (node.type === "TSQualifiedName" && node.left.type === "Identifier" && keywordNamespaces.has(node.left.name) && node.right.type === "Identifier") {
101
+ keywords.add(node.right.name);
102
+ }
103
+ }
104
+ });
105
+ return keywords;
106
+ };
107
+ var keywordConstPrefix = "_";
108
+ var createExportDeclaration = (keywords) => {
109
+ const aliases = [...keywords].map(
110
+ (key) => ` ${keywordConstPrefix}${key} as ${key},`
111
+ );
112
+ return [`export {`, ...aliases, `};`];
113
+ };
114
+ var generateTypesFile = async (collectedKeywords, root, dirname = ".keywords", filename = "types.d.ts") => {
115
+ const keywordDeclarations = [...collectedKeywords].map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`).map((line) => ` ${line}`).join("\n");
116
+ const exportDeclaration = createExportDeclaration(collectedKeywords).map((line) => ` ${line}`).join("\n");
117
+ const content = `declare module '${VIRTUAL_MODULE_ID}' {
118
+ ${keywordDeclarations}
119
+ ${exportDeclaration}
120
+ }`;
121
+ const pluginRoot = import_path.default.join(root, dirname);
122
+ await (0, import_promises.mkdir)(pluginRoot, { recursive: true });
123
+ await (0, import_promises.writeFile)(import_path.default.join(pluginRoot, filename), `${content.trim()}
124
+ `);
125
+ };
126
+ var collectKeywordsFromFiles = async (root, logger, ignoredDirs = []) => {
127
+ const collectedKeywords = /* @__PURE__ */ new Set();
128
+ logger.info("Scanning project files for keywords...");
129
+ const files = await (0, import_globby.globby)("**/*.{js,ts,jsx,tsx}", {
130
+ cwd: root,
131
+ absolute: true,
132
+ ignore: ["**/node_modules/**", ...ignoredDirs.map((dir) => `${dir}/**`)],
133
+ gitignore: true
134
+ });
135
+ await Promise.all(
136
+ files.map(async (file) => {
137
+ const code = await (0, import_promises.readFile)(file, "utf-8");
138
+ const keywords = extractKeywords(code);
139
+ for (const key of keywords) {
140
+ collectedKeywords.add(key);
141
+ }
142
+ })
143
+ );
144
+ logger.info(
145
+ `Scan complete. Found ${collectedKeywords.size} unique keywords.`
146
+ );
147
+ return collectedKeywords;
148
+ };
149
+ var collectKeywordsAndGenerateTypes = async (root, logger, ignoredDirs) => {
150
+ const collectedKeywords = await collectKeywordsFromFiles(
151
+ root,
152
+ logger,
153
+ ignoredDirs
154
+ );
155
+ await generateTypesFile(collectedKeywords, root);
156
+ return collectedKeywords;
157
+ };
158
+ var generateModuleCode = (collectedKeywords, isDev) => {
159
+ const symbolConstructorName = "__SYMBOL__";
160
+ const symbolDeclaration = `const ${symbolConstructorName} = Symbol;`;
161
+ const keywordDeclarations = [...collectedKeywords].map(
162
+ (key) => `const ${keywordConstPrefix}${key} = /* @__PURE__ */ ${symbolConstructorName}(${isDev ? `'${key}'` : ""});`
163
+ ).join("\n");
164
+ const exportDeclaration = createExportDeclaration(collectedKeywords).join("\n");
165
+ return `${symbolDeclaration}
166
+ ${keywordDeclarations}
167
+ ${exportDeclaration}
168
+ `;
169
+ };
170
+ var splitQuery = (id) => id.split("?");
28
171
 
29
172
  // src/shared.ts
30
173
  var PLUGIN_NAME = "rollup-plugin-keywords";
@@ -39,7 +182,7 @@ var keywordsPlugin = () => {
39
182
  name: PLUGIN_NAME,
40
183
  async buildStart() {
41
184
  const pluginThis = this;
42
- logger = (0, import_minifiable_keywords.createPrefixedLogger)(
185
+ logger = createPrefixedLogger(
43
186
  {
44
187
  info: pluginThis.info,
45
188
  warn: pluginThis.warn,
@@ -48,21 +191,21 @@ var keywordsPlugin = () => {
48
191
  PLUGIN_NAME,
49
192
  false
50
193
  );
51
- collectedKeywords = await (0, import_minifiable_keywords.collectKeywordsAndGenerateTypes)(root, logger);
194
+ collectedKeywords = await collectKeywordsAndGenerateTypes(root, logger);
52
195
  },
53
196
  resolveId(source, importer) {
54
197
  if (!importer) {
55
198
  return;
56
199
  }
57
- const [validSource] = (0, import_minifiable_keywords.splitQuery)(source);
58
- if (validSource === import_minifiable_keywords.VIRTUAL_MODULE_ID) {
59
- return import_minifiable_keywords.RESOLVED_VIRTUAL_MODULE_ID;
200
+ const [validSource] = splitQuery(source);
201
+ if (validSource === VIRTUAL_MODULE_ID) {
202
+ return RESOLVED_VIRTUAL_MODULE_ID;
60
203
  }
61
204
  },
62
205
  load(id) {
63
- const [validId] = (0, import_minifiable_keywords.splitQuery)(id);
64
- if (validId === import_minifiable_keywords.RESOLVED_VIRTUAL_MODULE_ID) {
65
- return (0, import_minifiable_keywords.generateModuleCode)(collectedKeywords, isDev);
206
+ const [validId] = splitQuery(id);
207
+ if (validId === RESOLVED_VIRTUAL_MODULE_ID) {
208
+ return generateModuleCode(collectedKeywords, isDev);
66
209
  }
67
210
  }
68
211
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/shared.ts"],"sourcesContent":["import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n generateModuleCode,\n RESOLVED_VIRTUAL_MODULE_ID,\n splitQuery,\n VIRTUAL_MODULE_ID,\n type PrefixedLogger,\n} from 'minifiable-keywords';\nimport type { Plugin } from 'rollup';\nimport { PLUGIN_NAME } from './shared';\n\nexport const keywordsPlugin = (): Plugin => {\n let collectedKeywords: Set<string>;\n let logger: PrefixedLogger;\n const root = process.cwd();\n const isDev = process.env.NODE_ENV === 'development';\n\n return {\n name: PLUGIN_NAME,\n\n async buildStart() {\n const pluginThis = this;\n logger = createPrefixedLogger(\n {\n info: pluginThis.info,\n warn: pluginThis.warn,\n error: pluginThis.error,\n },\n PLUGIN_NAME,\n false,\n );\n collectedKeywords = await collectKeywordsAndGenerateTypes(root, logger);\n },\n\n resolveId(source, importer) {\n if (!importer) {\n return;\n }\n const [validSource] = splitQuery(source);\n if (validSource === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n const [validId] = splitQuery(id);\n if (validId === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateModuleCode(collectedKeywords, isDev);\n }\n },\n };\n};\n\nexport default keywordsPlugin;\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAQO;;;ACRA,IAAM,cAAc;;;ADYpB,IAAM,iBAAiB,MAAc;AAC1C,MAAI;AACJ,MAAI;AACJ,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,aAAa;AACjB,YAAM,aAAa;AACnB,mBAAS;AAAA,QACP;AAAA,UACE,MAAM,WAAW;AAAA,UACjB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,0BAAoB,UAAM,4DAAgC,MAAM,MAAM;AAAA,IACxE;AAAA,IAEA,UAAU,QAAQ,UAAU;AAC1B,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,CAAC,WAAW,QAAI,uCAAW,MAAM;AACvC,UAAI,gBAAgB,8CAAmB;AACrC,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,YAAM,CAAC,OAAO,QAAI,uCAAW,EAAE;AAC/B,UAAI,YAAY,uDAA4B;AAC1C,mBAAO,+CAAmB,mBAAmB,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../../minifiable-keywords/src/index.ts","../src/shared.ts"],"sourcesContent":["import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n generateModuleCode,\n RESOLVED_VIRTUAL_MODULE_ID,\n splitQuery,\n VIRTUAL_MODULE_ID,\n type PrefixedLogger,\n} from 'minifiable-keywords';\nimport type { Plugin } from 'rollup';\nimport { PLUGIN_NAME } from './shared';\n\nexport const keywordsPlugin = (): Plugin => {\n let collectedKeywords: Set<string>;\n let logger: PrefixedLogger;\n const root = process.cwd();\n const isDev = process.env.NODE_ENV === 'development';\n\n return {\n name: PLUGIN_NAME,\n\n async buildStart() {\n const pluginThis = this;\n logger = createPrefixedLogger(\n {\n info: pluginThis.info,\n warn: pluginThis.warn,\n error: pluginThis.error,\n },\n PLUGIN_NAME,\n false,\n );\n collectedKeywords = await collectKeywordsAndGenerateTypes(root, logger);\n },\n\n resolveId(source, importer) {\n if (!importer) {\n return;\n }\n const [validSource] = splitQuery(source);\n if (validSource === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n const [validId] = splitQuery(id);\n if (validId === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateModuleCode(collectedKeywords, isDev);\n }\n },\n };\n};\n\nexport default keywordsPlugin;\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { parse } from '@babel/parser';\nimport _traverse, { type Node } from '@babel/traverse';\nimport { globby } from 'globby';\n\nexport const VIRTUAL_MODULE_ID = 'virtual:keywords';\nexport const RESOLVED_VIRTUAL_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`;\n\nexport interface Logger {\n info: (message: string) => void;\n warn: (message: string) => void;\n error: (message: string) => void;\n}\n\nexport interface PrefixedLogger extends Logger {\n pluginName: string;\n}\n\nexport const createPrefixedLogger = (\n logger: Logger,\n pluginName: string,\n usePrefix: boolean = true,\n): PrefixedLogger => {\n const prefix = usePrefix ? `[${pluginName}] ` : '';\n const prefixed = (message: string) => `${prefix}${message}`;\n return {\n pluginName,\n info: (message: string) => logger.info(prefixed(message)),\n warn: (message: string) => logger.warn(prefixed(message)),\n error: (message: string) => logger.error(prefixed(message)),\n };\n};\n\n// ref: https://github.com/babel/babel/discussions/13093\nconst traverse =\n typeof _traverse === 'function'\n ? _traverse\n : ((_traverse as any).default as typeof _traverse);\n\nexport const extractKeywords = (code: string): Set<string> => {\n const keywords = new Set<string>();\n\n let ast: Node;\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n });\n } catch (e) {\n return keywords;\n }\n\n const keywordNamespaces = new Set<string>();\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'ImportDeclaration' &&\n node.source.value === VIRTUAL_MODULE_ID\n ) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportNamespaceSpecifier') {\n keywordNamespaces.add(specifier.local.name);\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n keywords.add('default');\n }\n\n if (specifier.type === 'ImportSpecifier') {\n if (specifier.imported.type === 'Identifier') {\n keywords.add(specifier.imported.name);\n }\n }\n }\n }\n },\n });\n\n if (keywordNamespaces.size === 0) {\n return keywords;\n }\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'MemberExpression' &&\n !node.computed && // Exclude computed properties like K['xyz']\n node.object.type === 'Identifier' &&\n keywordNamespaces.has(node.object.name) &&\n node.property.type === 'Identifier'\n ) {\n keywords.add(node.property.name);\n }\n\n if (\n node.type === 'TSQualifiedName' &&\n node.left.type === 'Identifier' &&\n keywordNamespaces.has(node.left.name) &&\n node.right.type === 'Identifier'\n ) {\n keywords.add(node.right.name);\n }\n },\n });\n\n return keywords;\n};\n\nconst keywordConstPrefix = '_';\nconst createExportDeclaration = (keywords: Set<string>): string[] => {\n const aliases = [...keywords].map(\n (key) => ` ${keywordConstPrefix}${key} as ${key},`,\n );\n return [`export {`, ...aliases, `};`];\n};\n\nexport const generateTypesFile = async (\n collectedKeywords: Set<string>,\n root: string,\n dirname: string = '.keywords',\n filename: string = 'types.d.ts',\n): Promise<void> => {\n const keywordDeclarations = [...collectedKeywords]\n .map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`)\n .map((line) => ` ${line}`)\n .join('\\n');\n const exportDeclaration = createExportDeclaration(collectedKeywords)\n .map((line) => ` ${line}`)\n .join('\\n');\n const content = `declare module '${VIRTUAL_MODULE_ID}' {\\n${keywordDeclarations}\\n${exportDeclaration}\\n}`;\n const pluginRoot = path.join(root, dirname);\n await mkdir(pluginRoot, { recursive: true });\n await writeFile(path.join(pluginRoot, filename), `${content.trim()}\\n`);\n};\n\nexport const collectKeywordsFromFiles = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs: string[] = [],\n): Promise<Set<string>> => {\n const collectedKeywords = new Set<string>();\n\n logger.info('Scanning project files for keywords...');\n\n const files = await globby('**/*.{js,ts,jsx,tsx}', {\n cwd: root,\n absolute: true,\n ignore: ['**/node_modules/**', ...ignoredDirs.map((dir) => `${dir}/**`)],\n gitignore: true,\n });\n\n await Promise.all(\n files.map(async (file) => {\n const code = await readFile(file, 'utf-8');\n const keywords = extractKeywords(code);\n for (const key of keywords) {\n collectedKeywords.add(key);\n }\n }),\n );\n\n logger.info(\n `Scan complete. Found ${collectedKeywords.size} unique keywords.`,\n );\n\n return collectedKeywords;\n};\n\nexport const collectKeywordsAndGenerateTypes = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs?: string[],\n): Promise<Set<string>> => {\n const collectedKeywords = await collectKeywordsFromFiles(\n root,\n logger,\n ignoredDirs,\n );\n await generateTypesFile(collectedKeywords, root);\n return collectedKeywords;\n};\n\nexport const generateModuleCode = (\n collectedKeywords: Set<string>,\n isDev: boolean,\n): string => {\n const symbolConstructorName = '__SYMBOL__';\n const symbolDeclaration = `const ${symbolConstructorName} = Symbol;`;\n const keywordDeclarations = [...collectedKeywords]\n .map(\n (key) =>\n `const ${keywordConstPrefix}${key} = /* @__PURE__ */ ${symbolConstructorName}(${isDev ? `'${key}'` : ''});`,\n )\n .join('\\n');\n const exportDeclaration =\n createExportDeclaration(collectedKeywords).join('\\n');\n return `${symbolDeclaration}\\n${keywordDeclarations}\\n${exportDeclaration}\\n`;\n};\n\nexport const splitQuery = (id: string) => id.split('?');\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAA2C;AAC3C,kBAAiB;AACjB,oBAAsB;AACtB,sBAAqC;AACrC,oBAAuB;AAEhB,IAAM,oBAAoB;AAC1B,IAAM,6BAA6B,KAAK,iBAAiB;AAYzD,IAAM,uBAAuB,CAClC,QACA,YACA,YAAqB,SACF;AACnB,QAAM,SAAS,YAAY,IAAI,UAAU,OAAO;AAChD,QAAM,WAAW,CAAC,YAAoB,GAAG,MAAM,GAAG,OAAO;AACzD,SAAO;IACL;IACA,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,OAAO,CAAC;IACxD,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,OAAO,CAAC;IACxD,OAAO,CAAC,YAAoB,OAAO,MAAM,SAAS,OAAO,CAAC;EAC5D;AACF;AAGA,IAAM,WACJ,OAAO,gBAAAA,YAAc,aACjB,gBAAAA,UACE,gBAAAA,QAAkB;AAEnB,IAAM,kBAAkB,CAAC,SAA8B;AAC5D,QAAM,WAAW,oBAAI,IAAY;AAEjC,MAAI;AACJ,MAAI;AACF,cAAM,qBAAM,MAAM;MAChB,YAAY;MACZ,SAAS,CAAC,cAAc,KAAK;MAC7B,eAAe;IACjB,CAAC;EACH,SAAS,GAAG;AACV,WAAO;EACT;AAEA,QAAM,oBAAoB,oBAAI,IAAY;AAE1C,WAAS,KAAK;IACZ,MAAM,UAAU;AACd,YAAM,OAAO,SAAS;AAEtB,UACE,KAAK,SAAS,uBACd,KAAK,OAAO,UAAU,mBACtB;AACA,mBAAW,aAAa,KAAK,YAAY;AACvC,cAAI,UAAU,SAAS,4BAA4B;AACjD,8BAAkB,IAAI,UAAU,MAAM,IAAI;UAC5C;AAEA,cAA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AE,KAAK,IAAI;AACtD,SAAO,GAAG,iBAAiB;EAAK,mBAAmB;EAAK,iBAAiB;;AAC3E;AAEO,IAAM,aAAa,CAAC,OAAe,GAAG,MAAM,GAAG;;;AC9M/C,IAAM,cAAc;;;AFYpB,IAAM,iBAAiB,MAAc;AAC1C,MAAI;AACJ,MAAI;AACJ,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,aAAa;AACjB,YAAM,aAAa;AACnB,eAAS;AAAA,QACP;AAAA,UACE,MAAM,WAAW;AAAA,UACjB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,0BAAoB,MAAM,gCAAgC,MAAM,MAAM;AAAA,IACxE;AAAA,IAEA,UAAU,QAAQ,UAAU;AAC1B,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,CAAC,WAAW,IAAI,WAAW,MAAM;AACvC,UAAI,gBAAgB,mBAAmB;AACrC,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,YAAM,CAAC,OAAO,IAAI,WAAW,EAAE;AAC/B,UAAI,YAAY,4BAA4B;AAC1C,eAAO,mBAAmB,mBAAmB,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["_traverse","path"]}
package/dist/index.js CHANGED
@@ -1,12 +1,136 @@
1
- // src/index.ts
2
- import {
3
- collectKeywordsAndGenerateTypes,
4
- createPrefixedLogger,
5
- generateModuleCode,
6
- RESOLVED_VIRTUAL_MODULE_ID,
7
- splitQuery,
8
- VIRTUAL_MODULE_ID
9
- } from "minifiable-keywords";
1
+ // ../minifiable-keywords/dist/index.js
2
+ import { mkdir, readFile, writeFile } from "fs/promises";
3
+ import path from "path";
4
+ import { parse } from "@babel/parser";
5
+ import _traverse from "@babel/traverse";
6
+ import { globby } from "globby";
7
+ var VIRTUAL_MODULE_ID = "virtual:keywords";
8
+ var RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
9
+ var createPrefixedLogger = (logger, pluginName, usePrefix = true) => {
10
+ const prefix = usePrefix ? `[${pluginName}] ` : "";
11
+ const prefixed = (message) => `${prefix}${message}`;
12
+ return {
13
+ pluginName,
14
+ info: (message) => logger.info(prefixed(message)),
15
+ warn: (message) => logger.warn(prefixed(message)),
16
+ error: (message) => logger.error(prefixed(message))
17
+ };
18
+ };
19
+ var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
20
+ var extractKeywords = (code) => {
21
+ const keywords = /* @__PURE__ */ new Set();
22
+ let ast;
23
+ try {
24
+ ast = parse(code, {
25
+ sourceType: "module",
26
+ plugins: ["typescript", "jsx"],
27
+ errorRecovery: true
28
+ });
29
+ } catch (e) {
30
+ return keywords;
31
+ }
32
+ const keywordNamespaces = /* @__PURE__ */ new Set();
33
+ traverse(ast, {
34
+ enter(nodePath) {
35
+ const node = nodePath.node;
36
+ if (node.type === "ImportDeclaration" && node.source.value === VIRTUAL_MODULE_ID) {
37
+ for (const specifier of node.specifiers) {
38
+ if (specifier.type === "ImportNamespaceSpecifier") {
39
+ keywordNamespaces.add(specifier.local.name);
40
+ }
41
+ if (specifier.type === "ImportDefaultSpecifier") {
42
+ keywords.add("default");
43
+ }
44
+ if (specifier.type === "ImportSpecifier") {
45
+ if (specifier.imported.type === "Identifier") {
46
+ keywords.add(specifier.imported.name);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ });
53
+ if (keywordNamespaces.size === 0) {
54
+ return keywords;
55
+ }
56
+ traverse(ast, {
57
+ enter(nodePath) {
58
+ const node = nodePath.node;
59
+ if (node.type === "MemberExpression" && !node.computed && // Exclude computed properties like K['xyz']
60
+ node.object.type === "Identifier" && keywordNamespaces.has(node.object.name) && node.property.type === "Identifier") {
61
+ keywords.add(node.property.name);
62
+ }
63
+ if (node.type === "TSQualifiedName" && node.left.type === "Identifier" && keywordNamespaces.has(node.left.name) && node.right.type === "Identifier") {
64
+ keywords.add(node.right.name);
65
+ }
66
+ }
67
+ });
68
+ return keywords;
69
+ };
70
+ var keywordConstPrefix = "_";
71
+ var createExportDeclaration = (keywords) => {
72
+ const aliases = [...keywords].map(
73
+ (key) => ` ${keywordConstPrefix}${key} as ${key},`
74
+ );
75
+ return [`export {`, ...aliases, `};`];
76
+ };
77
+ var generateTypesFile = async (collectedKeywords, root, dirname = ".keywords", filename = "types.d.ts") => {
78
+ const keywordDeclarations = [...collectedKeywords].map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`).map((line) => ` ${line}`).join("\n");
79
+ const exportDeclaration = createExportDeclaration(collectedKeywords).map((line) => ` ${line}`).join("\n");
80
+ const content = `declare module '${VIRTUAL_MODULE_ID}' {
81
+ ${keywordDeclarations}
82
+ ${exportDeclaration}
83
+ }`;
84
+ const pluginRoot = path.join(root, dirname);
85
+ await mkdir(pluginRoot, { recursive: true });
86
+ await writeFile(path.join(pluginRoot, filename), `${content.trim()}
87
+ `);
88
+ };
89
+ var collectKeywordsFromFiles = async (root, logger, ignoredDirs = []) => {
90
+ const collectedKeywords = /* @__PURE__ */ new Set();
91
+ logger.info("Scanning project files for keywords...");
92
+ const files = await globby("**/*.{js,ts,jsx,tsx}", {
93
+ cwd: root,
94
+ absolute: true,
95
+ ignore: ["**/node_modules/**", ...ignoredDirs.map((dir) => `${dir}/**`)],
96
+ gitignore: true
97
+ });
98
+ await Promise.all(
99
+ files.map(async (file) => {
100
+ const code = await readFile(file, "utf-8");
101
+ const keywords = extractKeywords(code);
102
+ for (const key of keywords) {
103
+ collectedKeywords.add(key);
104
+ }
105
+ })
106
+ );
107
+ logger.info(
108
+ `Scan complete. Found ${collectedKeywords.size} unique keywords.`
109
+ );
110
+ return collectedKeywords;
111
+ };
112
+ var collectKeywordsAndGenerateTypes = async (root, logger, ignoredDirs) => {
113
+ const collectedKeywords = await collectKeywordsFromFiles(
114
+ root,
115
+ logger,
116
+ ignoredDirs
117
+ );
118
+ await generateTypesFile(collectedKeywords, root);
119
+ return collectedKeywords;
120
+ };
121
+ var generateModuleCode = (collectedKeywords, isDev) => {
122
+ const symbolConstructorName = "__SYMBOL__";
123
+ const symbolDeclaration = `const ${symbolConstructorName} = Symbol;`;
124
+ const keywordDeclarations = [...collectedKeywords].map(
125
+ (key) => `const ${keywordConstPrefix}${key} = /* @__PURE__ */ ${symbolConstructorName}(${isDev ? `'${key}'` : ""});`
126
+ ).join("\n");
127
+ const exportDeclaration = createExportDeclaration(collectedKeywords).join("\n");
128
+ return `${symbolDeclaration}
129
+ ${keywordDeclarations}
130
+ ${exportDeclaration}
131
+ `;
132
+ };
133
+ var splitQuery = (id) => id.split("?");
10
134
 
11
135
  // src/shared.ts
12
136
  var PLUGIN_NAME = "rollup-plugin-keywords";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/shared.ts"],"sourcesContent":["import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n generateModuleCode,\n RESOLVED_VIRTUAL_MODULE_ID,\n splitQuery,\n VIRTUAL_MODULE_ID,\n type PrefixedLogger,\n} from 'minifiable-keywords';\nimport type { Plugin } from 'rollup';\nimport { PLUGIN_NAME } from './shared';\n\nexport const keywordsPlugin = (): Plugin => {\n let collectedKeywords: Set<string>;\n let logger: PrefixedLogger;\n const root = process.cwd();\n const isDev = process.env.NODE_ENV === 'development';\n\n return {\n name: PLUGIN_NAME,\n\n async buildStart() {\n const pluginThis = this;\n logger = createPrefixedLogger(\n {\n info: pluginThis.info,\n warn: pluginThis.warn,\n error: pluginThis.error,\n },\n PLUGIN_NAME,\n false,\n );\n collectedKeywords = await collectKeywordsAndGenerateTypes(root, logger);\n },\n\n resolveId(source, importer) {\n if (!importer) {\n return;\n }\n const [validSource] = splitQuery(source);\n if (validSource === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n const [validId] = splitQuery(id);\n if (validId === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateModuleCode(collectedKeywords, isDev);\n }\n },\n };\n};\n\nexport default keywordsPlugin;\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACRA,IAAM,cAAc;;;ADYpB,IAAM,iBAAiB,MAAc;AAC1C,MAAI;AACJ,MAAI;AACJ,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,aAAa;AACjB,YAAM,aAAa;AACnB,eAAS;AAAA,QACP;AAAA,UACE,MAAM,WAAW;AAAA,UACjB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,0BAAoB,MAAM,gCAAgC,MAAM,MAAM;AAAA,IACxE;AAAA,IAEA,UAAU,QAAQ,UAAU;AAC1B,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,CAAC,WAAW,IAAI,WAAW,MAAM;AACvC,UAAI,gBAAgB,mBAAmB;AACrC,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,YAAM,CAAC,OAAO,IAAI,WAAW,EAAE;AAC/B,UAAI,YAAY,4BAA4B;AAC1C,eAAO,mBAAmB,mBAAmB,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../minifiable-keywords/src/index.ts","../src/shared.ts","../src/index.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { parse } from '@babel/parser';\nimport _traverse, { type Node } from '@babel/traverse';\nimport { globby } from 'globby';\n\nexport const VIRTUAL_MODULE_ID = 'virtual:keywords';\nexport const RESOLVED_VIRTUAL_MODULE_ID = `\\0${VIRTUAL_MODULE_ID}`;\n\nexport interface Logger {\n info: (message: string) => void;\n warn: (message: string) => void;\n error: (message: string) => void;\n}\n\nexport interface PrefixedLogger extends Logger {\n pluginName: string;\n}\n\nexport const createPrefixedLogger = (\n logger: Logger,\n pluginName: string,\n usePrefix: boolean = true,\n): PrefixedLogger => {\n const prefix = usePrefix ? `[${pluginName}] ` : '';\n const prefixed = (message: string) => `${prefix}${message}`;\n return {\n pluginName,\n info: (message: string) => logger.info(prefixed(message)),\n warn: (message: string) => logger.warn(prefixed(message)),\n error: (message: string) => logger.error(prefixed(message)),\n };\n};\n\n// ref: https://github.com/babel/babel/discussions/13093\nconst traverse =\n typeof _traverse === 'function'\n ? _traverse\n : ((_traverse as any).default as typeof _traverse);\n\nexport const extractKeywords = (code: string): Set<string> => {\n const keywords = new Set<string>();\n\n let ast: Node;\n try {\n ast = parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n errorRecovery: true,\n });\n } catch (e) {\n return keywords;\n }\n\n const keywordNamespaces = new Set<string>();\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'ImportDeclaration' &&\n node.source.value === VIRTUAL_MODULE_ID\n ) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportNamespaceSpecifier') {\n keywordNamespaces.add(specifier.local.name);\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n keywords.add('default');\n }\n\n if (specifier.type === 'ImportSpecifier') {\n if (specifier.imported.type === 'Identifier') {\n keywords.add(specifier.imported.name);\n }\n }\n }\n }\n },\n });\n\n if (keywordNamespaces.size === 0) {\n return keywords;\n }\n\n traverse(ast, {\n enter(nodePath) {\n const node = nodePath.node;\n\n if (\n node.type === 'MemberExpression' &&\n !node.computed && // Exclude computed properties like K['xyz']\n node.object.type === 'Identifier' &&\n keywordNamespaces.has(node.object.name) &&\n node.property.type === 'Identifier'\n ) {\n keywords.add(node.property.name);\n }\n\n if (\n node.type === 'TSQualifiedName' &&\n node.left.type === 'Identifier' &&\n keywordNamespaces.has(node.left.name) &&\n node.right.type === 'Identifier'\n ) {\n keywords.add(node.right.name);\n }\n },\n });\n\n return keywords;\n};\n\nconst keywordConstPrefix = '_';\nconst createExportDeclaration = (keywords: Set<string>): string[] => {\n const aliases = [...keywords].map(\n (key) => ` ${keywordConstPrefix}${key} as ${key},`,\n );\n return [`export {`, ...aliases, `};`];\n};\n\nexport const generateTypesFile = async (\n collectedKeywords: Set<string>,\n root: string,\n dirname: string = '.keywords',\n filename: string = 'types.d.ts',\n): Promise<void> => {\n const keywordDeclarations = [...collectedKeywords]\n .map((key) => `const ${keywordConstPrefix}${key}: unique symbol;`)\n .map((line) => ` ${line}`)\n .join('\\n');\n const exportDeclaration = createExportDeclaration(collectedKeywords)\n .map((line) => ` ${line}`)\n .join('\\n');\n const content = `declare module '${VIRTUAL_MODULE_ID}' {\\n${keywordDeclarations}\\n${exportDeclaration}\\n}`;\n const pluginRoot = path.join(root, dirname);\n await mkdir(pluginRoot, { recursive: true });\n await writeFile(path.join(pluginRoot, filename), `${content.trim()}\\n`);\n};\n\nexport const collectKeywordsFromFiles = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs: string[] = [],\n): Promise<Set<string>> => {\n const collectedKeywords = new Set<string>();\n\n logger.info('Scanning project files for keywords...');\n\n const files = await globby('**/*.{js,ts,jsx,tsx}', {\n cwd: root,\n absolute: true,\n ignore: ['**/node_modules/**', ...ignoredDirs.map((dir) => `${dir}/**`)],\n gitignore: true,\n });\n\n await Promise.all(\n files.map(async (file) => {\n const code = await readFile(file, 'utf-8');\n const keywords = extractKeywords(code);\n for (const key of keywords) {\n collectedKeywords.add(key);\n }\n }),\n );\n\n logger.info(\n `Scan complete. Found ${collectedKeywords.size} unique keywords.`,\n );\n\n return collectedKeywords;\n};\n\nexport const collectKeywordsAndGenerateTypes = async (\n root: string,\n logger: PrefixedLogger,\n ignoredDirs?: string[],\n): Promise<Set<string>> => {\n const collectedKeywords = await collectKeywordsFromFiles(\n root,\n logger,\n ignoredDirs,\n );\n await generateTypesFile(collectedKeywords, root);\n return collectedKeywords;\n};\n\nexport const generateModuleCode = (\n collectedKeywords: Set<string>,\n isDev: boolean,\n): string => {\n const symbolConstructorName = '__SYMBOL__';\n const symbolDeclaration = `const ${symbolConstructorName} = Symbol;`;\n const keywordDeclarations = [...collectedKeywords]\n .map(\n (key) =>\n `const ${keywordConstPrefix}${key} = /* @__PURE__ */ ${symbolConstructorName}(${isDev ? `'${key}'` : ''});`,\n )\n .join('\\n');\n const exportDeclaration =\n createExportDeclaration(collectedKeywords).join('\\n');\n return `${symbolDeclaration}\\n${keywordDeclarations}\\n${exportDeclaration}\\n`;\n};\n\nexport const splitQuery = (id: string) => id.split('?');\n","export const PLUGIN_NAME = 'rollup-plugin-keywords';\n","import {\n collectKeywordsAndGenerateTypes,\n createPrefixedLogger,\n generateModuleCode,\n RESOLVED_VIRTUAL_MODULE_ID,\n splitQuery,\n VIRTUAL_MODULE_ID,\n type PrefixedLogger,\n} from 'minifiable-keywords';\nimport type { Plugin } from 'rollup';\nimport { PLUGIN_NAME } from './shared';\n\nexport const keywordsPlugin = (): Plugin => {\n let collectedKeywords: Set<string>;\n let logger: PrefixedLogger;\n const root = process.cwd();\n const isDev = process.env.NODE_ENV === 'development';\n\n return {\n name: PLUGIN_NAME,\n\n async buildStart() {\n const pluginThis = this;\n logger = createPrefixedLogger(\n {\n info: pluginThis.info,\n warn: pluginThis.warn,\n error: pluginThis.error,\n },\n PLUGIN_NAME,\n false,\n );\n collectedKeywords = await collectKeywordsAndGenerateTypes(root, logger);\n },\n\n resolveId(source, importer) {\n if (!importer) {\n return;\n }\n const [validSource] = splitQuery(source);\n if (validSource === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n const [validId] = splitQuery(id);\n if (validId === RESOLVED_VIRTUAL_MODULE_ID) {\n return generateModuleCode(collectedKeywords, isDev);\n }\n },\n };\n};\n\nexport default keywordsPlugin;\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,OAAO,eAA8B;AACrC,SAAS,cAAc;AAEhB,IAAM,oBAAoB;AAC1B,IAAM,6BAA6B,KAAK,iBAAiB;AAYzD,IAAM,uBAAuB,CAClC,QACA,YACA,YAAqB,SACF;AACnB,QAAM,SAAS,YAAY,IAAI,UAAU,OAAO;AAChD,QAAM,WAAW,CAAC,YAAoB,GAAG,MAAM,GAAG,OAAO;AACzD,SAAO;IACL;IACA,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,OAAO,CAAC;IACxD,MAAM,CAAC,YAAoB,OAAO,KAAK,SAAS,OAAO,CAAC;IACxD,OAAO,CAAC,YAAoB,OAAO,MAAM,SAAS,OAAO,CAAC;EAC5D;AACF;AAGA,IAAM,WACJ,OAAO,cAAc,aACjB,YACE,UAAkB;AAEnB,IAAM,kBAAkB,CAAC,SAA8B;AAC5D,QAAM,WAAW,oBAAI,IAAY;AAEjC,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,MAAM;MAChB,YAAY;MACZ,SAAS,CAAC,cAAc,KAAK;MAC7B,eAAe;IACjB,CAAC;EACH,SAAS,GAAG;AACV,WAAO;EACT;AAEA,QAAM,oBAAoB,oBAAI,IAAY;AAE1C,WAAS,KAAK;IACZ,MAAM,UAAU;AACd,YAAM,OAAO,SAAS;AAEtB,UACE,KAAK,SAAS,uBACd,KAAK,OAAO,UAAU,mBACtB;AACA,mBAAW,aAAa,KAAK,YAAY;AACvC,cAAI,UAAU,SAAS,4BAA4B;AACjD,8BAAkB,IAAI,UAAU,MAAM,IAAI;UAC5C;AAEA,cAAI,UAAU,SAAS,0BAA0B;AAC/C,qBAAS,IAAI,SAAS;UACxB;AAEA,cAAI,UA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M,aAAa,CAAC,OAAe,GAAG,MAAM,GAAG;;;AC9M/C,IAAM,cAAc;;;ACYpB,IAAM,iBAAiB,MAAc;AAC1C,MAAI;AACJ,MAAI;AACJ,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,aAAa;AACjB,YAAM,aAAa;AACnB,eAAS;AAAA,QACP;AAAA,UACE,MAAM,WAAW;AAAA,UACjB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,0BAAoB,MAAM,gCAAgC,MAAM,MAAM;AAAA,IACxE;AAAA,IAEA,UAAU,QAAQ,UAAU;AAC1B,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,CAAC,WAAW,IAAI,WAAW,MAAM;AACvC,UAAI,gBAAgB,mBAAmB;AACrC,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,YAAM,CAAC,OAAO,IAAI,WAAW,EAAE;AAC/B,UAAI,YAAY,4BAA4B;AAC1C,eAAO,mBAAmB,mBAAmB,KAAK;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-keywords",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A Rollup plugin that provides minifiable Symbols (keywords) to use in place of string literals for aggressive minification/obfuscation.",
5
5
  "keywords": [
6
6
  "rollup",
@@ -37,13 +37,16 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "minifiable-keywords": "1.0.1"
40
+ "@babel/parser": "^7.28.0",
41
+ "@babel/traverse": "^7.28.0",
42
+ "globby": "^16.0.0"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@types/node": "^24.1.0",
44
46
  "rimraf": "^6.0.1",
45
47
  "tsup": "^8.5.0",
46
- "vitest": "^3.2.4"
48
+ "vitest": "^4.0.0",
49
+ "minifiable-keywords": "1.0.2"
47
50
  },
48
51
  "peerDependencies": {
49
52
  "rollup": "^3.0.0 || ^4.0.0"