vite-plugin-strip-comments 0.0.2 → 0.0.3
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +14 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const c={type:"istanbul",enforce:"pre"},
|
|
1
|
+
"use strict";const c={type:"istanbul",enforce:"pre"},i=(s={})=>{const o={type:["none","keep-legal","istanbul"].some(e=>e===s.type)?s.type:c.type,enforce:["pre","post"].some(e=>e===s.enforce)?s.enforce:c.enforce};return{name:"vite-plugin-strip-comments",enforce:o.enforce,transform(e,r){if(!r||r.includes("node_modules")||!/\.([jt]sx?)$/.test(r))return{code:e,map:null};let t=e,n;const a=Array.from(e.matchAll(/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|\/\/.*(?=\n)?/gm));for(let l=0;l<a.length;l+=1)switch([n]=a[l],o.type){case"keep-legal":["@legal","@license"].some(p=>n.includes(p))||(t=t.replace(n,""));break;case"istanbul":n.includes("istanbul")&&(t=t.replace(n,""));break;case"none":default:t=t.replace(n,"")}return{code:t,map:null}}}};module.exports=i;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => string;\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string) {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\")) return code;\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string): { code: string; map: null } {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\") || !/\\.([jt]sx?)$/.test(id)) {\n return { code, map: null };\n }\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|\\/\\/.*(?=\\n)?/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // first match\n [match] = matchesArray[i];\n\n switch (config.type) {\n case \"keep-legal\":\n if (![\"@legal\", \"@license\"].some((x) => match.includes(x))) {\n result = result.replace(match, \"\");\n }\n break;\n case \"istanbul\":\n if (match.includes(\"istanbul\")) {\n /* istanbul ignore next @preserve */\n result = result.replace(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replace(match, \"\");\n }\n }\n\n return { code: result, map: null };\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"aAmBA,MAAMA,EAAkD,CACtD,KAAM,WACN,QAAS,KACX,EAEMC,EAAgB,CAACC,EAAoC,KAAO,CAChE,MAAMC,EAAuC,CAC3C,KACG,CAAC,OAAQ,aAAc,UAAU,EAAE,KAAMC,GAAMA,IAAMF,EAAI,IAAI,EAC1DA,EAAI,KACJF,EAA2B,KACjC,QACG,CAAC,MAAO,MAAM,EAAE,KAAMI,GAAMA,IAAMF,EAAI,OAAO,EAC1CA,EAAI,QACJF,EAA2B,OACnC,EAEO,MAAA,CACL,KAAM,6BACN,QAASG,EAAO,QAChB,UAAUE,EAAcC,EAA0C,CAE5D,GAAA,CAACA,GAAMA,EAAG,SAAS,cAAc,GAAK,CAAC,eAAe,KAAKA,CAAE,EACxD,MAAA,CAAE,KAAAD,EAAM,IAAK,IAAK,EAE3B,IAAIE,EAASF,EACTG,EAEE,MAAAC,EAAe,MAAM,KAAKJ,EAAK,SACnC,gDAAA,CACD,EAED,QAASK,EAAI,EAAGA,EAAID,EAAa,OAAQC,GAAK,EAI5C,OAFC,CAAAF,CAAK,EAAIC,EAAaC,CAAC,EAEhBP,EAAO,KAAM,CACnB,IAAK,aACE,CAAC,SAAU,UAAU,EAAE,KAAMC,GAAMI,EAAM,SAASJ,CAAC,CAAC,IAC9CG,EAAAA,EAAO,QAAQC,EAAO,EAAE,GAEnC,MACF,IAAK,WACCA,EAAM,SAAS,UAAU,IAElBD,EAAAA,EAAO,QAAQC,EAAO,EAAE,GAEnC,MACF,IAAK,OACL,QACWD,EAAAA,EAAO,QAAQC,EAAO,EAAE,CAAA,CAIvC,MAAO,CAAE,KAAMD,EAAQ,IAAK,IAAK,CAAA,CAErC,CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
declare const stripComments: (cfg?: Partial<StripCommentsConfig>) => {
|
|
2
2
|
name: string;
|
|
3
3
|
enforce: "pre" | "post" | undefined;
|
|
4
|
-
transform(code: string, id?: string):
|
|
4
|
+
transform(code: string, id?: string): {
|
|
5
|
+
code: string;
|
|
6
|
+
map: null;
|
|
7
|
+
};
|
|
5
8
|
};
|
|
6
9
|
export default stripComments;
|
|
7
10
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
const c = {
|
|
2
2
|
type: "istanbul",
|
|
3
3
|
enforce: "pre"
|
|
4
|
-
},
|
|
5
|
-
const
|
|
4
|
+
}, m = (l = {}) => {
|
|
5
|
+
const a = {
|
|
6
6
|
type: ["none", "keep-legal", "istanbul"].some((e) => e === l.type) ? l.type : c.type,
|
|
7
7
|
enforce: ["pre", "post"].some((e) => e === l.enforce) ? l.enforce : c.enforce
|
|
8
8
|
};
|
|
9
9
|
return {
|
|
10
10
|
name: "vite-plugin-strip-comments",
|
|
11
|
-
enforce:
|
|
12
|
-
transform(e,
|
|
13
|
-
if (!
|
|
11
|
+
enforce: a.enforce,
|
|
12
|
+
transform(e, r) {
|
|
13
|
+
if (!r || r.includes("node_modules") || !/\.([jt]sx?)$/.test(r))
|
|
14
|
+
return { code: e, map: null };
|
|
14
15
|
let t = e, n;
|
|
15
16
|
const o = Array.from(e.matchAll(
|
|
16
|
-
/\/\*[\s\S]
|
|
17
|
+
/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|\/\/.*(?=\n)?/gm
|
|
17
18
|
));
|
|
18
|
-
for (let
|
|
19
|
-
switch ([n] = o[
|
|
19
|
+
for (let s = 0; s < o.length; s += 1)
|
|
20
|
+
switch ([n] = o[s], a.type) {
|
|
20
21
|
case "keep-legal":
|
|
21
|
-
["@legal", "@license"].some((
|
|
22
|
+
["@legal", "@license"].some((p) => n.includes(p)) || (t = t.replace(n, ""));
|
|
22
23
|
break;
|
|
23
24
|
case "istanbul":
|
|
24
|
-
n.includes("istanbul") && (t = t.
|
|
25
|
+
n.includes("istanbul") && (t = t.replace(n, ""));
|
|
25
26
|
break;
|
|
26
27
|
case "none":
|
|
27
28
|
default:
|
|
28
|
-
t = t.
|
|
29
|
+
t = t.replace(n, "");
|
|
29
30
|
}
|
|
30
|
-
return t;
|
|
31
|
+
return { code: t, map: null };
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
export {
|
|
35
|
-
|
|
36
|
+
m as default
|
|
36
37
|
};
|
|
37
38
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => string;\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string) {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\")) return code;\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string): { code: string; map: null } {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\") || !/\\.([jt]sx?)$/.test(id)) {\n return { code, map: null };\n }\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|\\/\\/.*(?=\\n)?/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // first match\n [match] = matchesArray[i];\n\n switch (config.type) {\n case \"keep-legal\":\n if (![\"@legal\", \"@license\"].some((x) => match.includes(x))) {\n result = result.replace(match, \"\");\n }\n break;\n case \"istanbul\":\n if (match.includes(\"istanbul\")) {\n /* istanbul ignore next @preserve */\n result = result.replace(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replace(match, \"\");\n }\n }\n\n return { code: result, map: null };\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"AAmBA,MAAMA,IAAkD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AACX,GAEMC,IAAgB,CAACC,IAAoC,OAAO;AAChE,QAAMC,IAAuC;AAAA,IAC3C,MACG,CAAC,QAAQ,cAAc,UAAU,EAAE,KAAK,CAACC,MAAMA,MAAMF,EAAI,IAAI,IAC1DA,EAAI,OACJF,EAA2B;AAAA,IACjC,SACG,CAAC,OAAO,MAAM,EAAE,KAAK,CAACI,MAAMA,MAAMF,EAAI,OAAO,IAC1CA,EAAI,UACJF,EAA2B;AAAA,EACnC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAASG,EAAO;AAAA,IAChB,UAAUE,GAAcC,GAA0C;AAE5D,UAAA,CAACA,KAAMA,EAAG,SAAS,cAAc,KAAK,CAAC,eAAe,KAAKA,CAAE;AACxD,eAAA,EAAE,MAAAD,GAAM,KAAK,KAAK;AAE3B,UAAIE,IAASF,GACTG;AAEE,YAAAC,IAAe,MAAM,KAAKJ,EAAK;AAAA,QACnC;AAAA,MAAA,CACD;AAED,eAASK,IAAI,GAAGA,IAAID,EAAa,QAAQC,KAAK;AAI5C,gBAFC,CAAAF,CAAK,IAAIC,EAAaC,CAAC,GAEhBP,EAAO,MAAM;AAAA,UACnB,KAAK;AACH,YAAK,CAAC,UAAU,UAAU,EAAE,KAAK,CAACC,MAAMI,EAAM,SAASJ,CAAC,CAAC,MAC9CG,IAAAA,EAAO,QAAQC,GAAO,EAAE;AAEnC;AAAA,UACF,KAAK;AACC,YAAAA,EAAM,SAAS,UAAU,MAElBD,IAAAA,EAAO,QAAQC,GAAO,EAAE;AAEnC;AAAA,UACF,KAAK;AAAA,UACL;AACW,YAAAD,IAAAA,EAAO,QAAQC,GAAO,EAAE;AAAA,QAAA;AAIvC,aAAO,EAAE,MAAMD,GAAQ,KAAK,KAAK;AAAA,IAAA;AAAA,EAErC;AACF;"}
|