@castlenine/vite-remove-attribute 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2024 Alexandre "Castlenine"
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ <div align="center">
2
+
3
+ # `@castlenine/vite-remove-attribute`
4
+
5
+ [![npm.badge]][npm] [![download.badge]][download]
6
+
7
+ Vite plugin that allows the removal of specified attributes and supports a variety of options, including file extensions, attributes, ignored folders, and files.
8
+ </div>
9
+
10
+ ## Table of Contents
11
+
12
+ - [Features](#features)
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [Prerequisites](#prerequisites)
16
+ - [Examples](#examples)
17
+
18
+ ## Features
19
+
20
+ - Removes specified attributes
21
+ - Allows you to specify the file extensions to be processed
22
+ - Can ignore certain folders or files based on configuration
23
+ - Ensures clean production code by removing unnecessary attributes, like 'data-testid' used in testing
24
+
25
+ ## Installation
26
+
27
+ Use your package manager to install:
28
+
29
+ ```shell
30
+ npm i --save-dev @castlenine/vite-remove-attribute
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Prerequisites
36
+
37
+ To use this plugin, you need to have a Vite project set up. Import and use the plugin in your `vite.config.js` or
38
+ `vite.config.ts` file.
39
+
40
+ ## Examples
41
+
42
+ ### Example 1: Removing 'data-testid' attributes from `.svelte` files
43
+
44
+ This configuration will remove `data-testid` attributes from all `.svelte` files in the production build.
45
+
46
+ ```typescript
47
+ import { defineConfig } from 'vite';
48
+ import { sveltekit } from '@sveltejs/kit/vite';
49
+
50
+ import removeAttribute from '@castlenine/vite-remove-attribute';
51
+
52
+ const IS_PRODUCTION = process.env.NODE_ENV == 'production';
53
+
54
+ export default defineConfig({
55
+ plugins: [
56
+ sveltekit(),
57
+
58
+ IS_PRODUCTION
59
+ ? removeAttribute({
60
+ extensions: ['svelte'],
61
+ attributes: ['data-testid'],
62
+ })
63
+ : null,
64
+ ],
65
+ });
66
+ ```
67
+
68
+ ### Example 2: Ignoring specific folders and files
69
+
70
+ This configuration will remove `data-testid` and `data-id` attributes from all `.svelte`, `.ts`, and `.js` files, with the exception of those located in the `src/tests` and `src/utilities` folders, as well as the `Header.svelte`, `src/components/Modal.svelte`, and `src/layouts/LayoutAuth.svelte` files in all builds.
71
+
72
+ ```typescript
73
+ import { defineConfig } from 'vite';
74
+ import { sveltekit } from '@sveltejs/kit/vite';
75
+
76
+ import removeAttribute from '@castlenine/vite-remove-attribute';
77
+
78
+ export default defineConfig({
79
+ plugins: [
80
+ sveltekit(),
81
+ removeAttribute({
82
+ extensions: ['svelte', 'ts', 'js'],
83
+ attributes: ['data-testid', 'data-id'],
84
+ ignoreFolders: ['src/tests', 'src/utilities'],
85
+ ignoreFiles: ['Header.svelte', 'src/components/Modal.svelte', 'src/layouts/LayoutAuth.svelte'],
86
+ }),
87
+ ],
88
+ });
89
+ ```
90
+
91
+ <br />
92
+
93
+ Forked from [mustafadalga/remove-attr](https://github.com/mustafadalga/remove-attr)
94
+
95
+ [npm]: https://www.npmjs.com/package/@castlenine/vite-remove-attribute
96
+ [npm.badge]: https://img.shields.io/npm/v/@castlenine/vite-remove-attribute
97
+ [download]: https://www.npmjs.com/package/@castlenine/vite-remove-attribute
98
+ [download.badge]: https://img.shields.io/npm/d18m/@castlenine/vite-remove-attribute
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { Options } from './types';
3
+ export default function removeAttributesPlugin(options: Options): Plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIvC,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAiBvE"}
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ const g = [
2
+ // Node modules
3
+ "node_modules",
4
+ // Git
5
+ ".git",
6
+ // IDE configurations
7
+ ".idea",
8
+ // JetBrains IDEs (e.g., WebStorm)
9
+ ".vscode",
10
+ // Visual Studio Code
11
+ // OS generated files
12
+ ".DS_Store",
13
+ // macOS
14
+ "Thumbs.db",
15
+ // Windows
16
+ // Environment variables
17
+ ".env",
18
+ ".env.*",
19
+ // .env.development, .env.production, etc.
20
+ // Logs
21
+ "logs",
22
+ "*.log",
23
+ // Svelte
24
+ "public",
25
+ // Svelte.js public folder
26
+ "build",
27
+ // Svelte.js build folder
28
+ // SvelteKit
29
+ ".svelte-kit",
30
+ // SvelteKit generates this folder
31
+ // Dist
32
+ "dist",
33
+ // Distribution folder
34
+ // Vue.js
35
+ ".nuxt",
36
+ // Nuxt.js generates this folder
37
+ // React.js
38
+ ".next",
39
+ // Next.js generates this folder
40
+ // Remix.js
41
+ ".remix",
42
+ // Remix.js cache
43
+ // Angular
44
+ "e2e",
45
+ // End-to-end tests in Angular
46
+ "angular.json",
47
+ // Angular CLI configuration
48
+ "browserslist",
49
+ // Browser compatibility list for Angular
50
+ ".cache"
51
+ // Cache files for various tools
52
+ ];
53
+ function a(e) {
54
+ return {
55
+ extensions: Array.isArray(e.extensions) ? e.extensions : [],
56
+ ignoreFolders: Array.isArray(e.ignoreFolders) ? e.ignoreFolders : [],
57
+ ignoreFiles: Array.isArray(e.ignoreFiles) ? e.ignoreFiles : [],
58
+ attributes: Array.isArray(e.attributes) ? e.attributes : []
59
+ };
60
+ }
61
+ function E(e) {
62
+ const n = [".", "./", "/", "/."], r = l(e.ignoreFolders || [], n).filter((s) => d(s)), t = l(e.ignoreFiles || [], n).filter((s) => c(s));
63
+ return r.concat(t);
64
+ }
65
+ function f(e) {
66
+ return !!e && typeof e == "string";
67
+ }
68
+ function o(e) {
69
+ return e.trim().startsWith("./") ? e.substring(2) : e.trim();
70
+ }
71
+ function u(e, n) {
72
+ return (n ?? g).some((r) => e.includes(r));
73
+ }
74
+ function l(e, n) {
75
+ return [...new Set(e.filter((r) => !n.includes(r) && f(r) && o(r).length).map(o))];
76
+ }
77
+ function c(e) {
78
+ var n;
79
+ const [r, ...t] = ((n = e.split("/").pop()) !== null && n !== void 0 ? n : "").split(".");
80
+ return e.length >= 3 && t.length >= 2 && r.length >= 3 && !r.includes("/");
81
+ }
82
+ function d(e) {
83
+ return !c(e) && /^[a-zA-Z0-9_.-/]*$/.test(e);
84
+ }
85
+ function A(e, n) {
86
+ return new RegExp(`\\.(${n.extensions.join("|")})$`, "i").test(e);
87
+ }
88
+ function I(e, n) {
89
+ return n.reduce((r, t) => {
90
+ const i = new RegExp(`(\\s(:|v-bind:)?${t}\\s*=\\s*(['"\`])((?:(?!\\3).)*)(\\3))|(\\s(:|v-bind:)?${t}(?=[\\s>]))`, "gi");
91
+ return r.replace(i, "");
92
+ }, e);
93
+ }
94
+ function _(e) {
95
+ const n = a(e), r = E(n);
96
+ return {
97
+ name: "remove-attributes",
98
+ enforce: "pre",
99
+ transform(t, i) {
100
+ return u(i) || u(i, r) || !A(i, n) ? t : I(t, n.attributes);
101
+ }
102
+ };
103
+ }
104
+ export {
105
+ _ as default
106
+ };
@@ -0,0 +1 @@
1
+ (function(s,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(s=typeof globalThis<"u"?globalThis:s||self,s.RemoveAttributesPlugin=o())})(this,function(){"use strict";const s=["node_modules",".git",".idea",".vscode",".DS_Store","Thumbs.db",".env",".env.*","logs","*.log","public","build",".svelte-kit","dist",".nuxt",".next",".remix","e2e","angular.json","browserslist",".cache"];function o(e){return{extensions:Array.isArray(e.extensions)?e.extensions:[],ignoreFolders:Array.isArray(e.ignoreFolders)?e.ignoreFolders:[],ignoreFiles:Array.isArray(e.ignoreFiles)?e.ignoreFiles:[],attributes:Array.isArray(e.attributes)?e.attributes:[]}}function d(e){const n=[".","./","/","/."],t=f(e.ignoreFolders||[],n).filter(u=>a(u)),r=f(e.ignoreFiles||[],n).filter(u=>g(u));return t.concat(r)}function E(e){return!!e&&typeof e=="string"}function l(e){return e.trim().startsWith("./")?e.substring(2):e.trim()}function c(e,n){return(n??s).some(t=>e.includes(t))}function f(e,n){return[...new Set(e.filter(t=>!n.includes(t)&&E(t)&&l(t).length).map(l))]}function g(e){var n;const[t,...r]=((n=e.split("/").pop())!==null&&n!==void 0?n:"").split(".");return e.length>=3&&r.length>=2&&t.length>=3&&!t.includes("/")}function a(e){return!g(e)&&/^[a-zA-Z0-9_.-/]*$/.test(e)}function A(e,n){return new RegExp(`\\.(${n.extensions.join("|")})$`,"i").test(e)}function I(e,n){return n.reduce((t,r)=>{const i=new RegExp(`(\\s(:|v-bind:)?${r}\\s*=\\s*(['"\`])((?:(?!\\3).)*)(\\3))|(\\s(:|v-bind:)?${r}(?=[\\s>]))`,"gi");return t.replace(i,"")},e)}function _(e){const n=o(e),t=d(n);return{name:"remove-attributes",enforce:"pre",transform(r,i){return c(i)||c(i,t)||!A(i,n)?r:I(r,n.attributes)}}}return _});
@@ -0,0 +1,8 @@
1
+ interface Options {
2
+ extensions: string[];
3
+ attributes: string[];
4
+ ignoreFolders?: string[];
5
+ ignoreFiles?: string[];
6
+ }
7
+ export type { Options };
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,UAAU,OAAO;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,YAAY,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Options } from './types';
2
+ export declare function getOptions(options: Options): Options;
3
+ export declare function getIgnoredPaths(options: Options): string[];
4
+ export declare function isString(path: string): boolean;
5
+ export declare function cleanString(path: string): string;
6
+ export declare function hasIgnorePath(id: string, paths?: string[]): boolean;
7
+ export declare function cleanIgnoredPaths(paths: string[], inValidPaths: string[]): string[];
8
+ export declare function isFile(path: string): boolean;
9
+ export declare function isFolder(path: string): boolean;
10
+ export declare function hasExtension(id: string, options: Options): boolean;
11
+ export declare function removeAttributes(input: string, attributes: string[]): string;
12
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAoDvC,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAOpD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAO1D;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAEnE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEnF;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG5C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG9C;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAIlE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAM5E"}
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@castlenine/vite-remove-attribute",
3
+ "version": "1.0.0",
4
+ "description": "A Vite plugin that enables the removal of specified attributes, which is useful for excluding attributes like 'data-testid' that are used in testing. The options include the ability to specify file extensions, attributes, and folders and files to ignore.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "attribute",
8
+ "attributes",
9
+ "build-tool",
10
+ "build",
11
+ "optimization",
12
+ "plugin",
13
+ "react",
14
+ "reactjs",
15
+ "remove-attribute",
16
+ "remove-attributes",
17
+ "remove",
18
+ "svelte",
19
+ "sveltekit",
20
+ "tool",
21
+ "typescript",
22
+ "vite-plugin",
23
+ "vite",
24
+ "vue.js",
25
+ "vue",
26
+ "web-development"
27
+ ],
28
+ "author": {
29
+ "name": "Alexandre Castlenine",
30
+ "url": "https://github.com/Castlenine"
31
+ },
32
+ "homepage": "https://github.com/castlenine/vite-remove-attribute",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/castlenine/vite-remove-attribute.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/castlenine/vite-remove-attribute/issues"
39
+ },
40
+ "type": "module",
41
+ "types": "dist/index.d.ts",
42
+ "main": "./dist/index.umd.cjs",
43
+ "module": "./dist/index.js",
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.ts",
47
+ "import": "./dist/index.js",
48
+ "require": "./dist/index.umd.cjs"
49
+ }
50
+ },
51
+ "files": [
52
+ "dist"
53
+ ],
54
+ "scripts": {
55
+ "dev": "vite dev",
56
+ "build": "vite build",
57
+ "preview": "vite preview",
58
+ "package": "npm run remove-dist-folder && npm run build && publint",
59
+ "prepublishOnly": "npm run package",
60
+ "eslint": "eslint --ignore-path ./.eslintignore .",
61
+ "eslint:fix": "eslint --fix --ignore-path ./.eslintignore .",
62
+ "prettier": "prettier --ignore-path ./.prettierignore --check .",
63
+ "prettier:fix": "prettier --ignore-path ./.prettierignore --write .",
64
+ "clean-code": "npm run prettier:fix && npm run eslint:fix",
65
+ "remove-dist-folder": "rimraf dist",
66
+ "publish-package": "npm publish -access public"
67
+ },
68
+ "peerDependencies": {
69
+ "vite": ">=2.0.0"
70
+ },
71
+ "devDependencies": {
72
+ "@rollup/plugin-typescript": "^11.1.6",
73
+ "@types/node": "^20.12.11",
74
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
75
+ "@typescript-eslint/parser": "^7.8.0",
76
+ "eslint": "^8.57.0",
77
+ "eslint-config-prettier": "^9.1.0",
78
+ "eslint-import-resolver-typescript": "^3.6.1",
79
+ "eslint-plugin-import": "^2.29.1",
80
+ "eslint-plugin-no-loops": "^0.3.0",
81
+ "eslint-plugin-only-warn": "^1.1.0",
82
+ "eslint-plugin-prettier": "^5.1.3",
83
+ "eslint-plugin-security": "^1.7.1",
84
+ "prettier": "^3.2.5",
85
+ "prettier-eslint": "^16.3.0",
86
+ "prettier-eslint-cli": "^8.0.1",
87
+ "publint": "^0.2.7",
88
+ "rimraf": "^5.0.5",
89
+ "tslib": "^2.6.2",
90
+ "typescript": "^5.4.5",
91
+ "vite": "^4.5.3"
92
+ }
93
+ }