@unlockable/vite-plugin-unlock 0.1.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 +21 -0
- package/README.md +346 -0
- package/dist/index.cjs +809 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +772 -0
- package/dist/index.js.map +1 -0
- package/dist/medusa.cjs +136 -0
- package/dist/medusa.cjs.map +1 -0
- package/dist/medusa.d.cts +75 -0
- package/dist/medusa.d.ts +75 -0
- package/dist/medusa.js +109 -0
- package/dist/medusa.js.map +1 -0
- package/dist/types-C3wWFKIK.d.cts +105 -0
- package/dist/types-C3wWFKIK.d.ts +105 -0
- package/package.json +77 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMR configuration for an unbundled target.
|
|
3
|
+
*
|
|
4
|
+
* When a package is excluded from pre-bundling (optimizeDeps.exclude),
|
|
5
|
+
* Vite loses the pre-bundled HMR boundary and processes raw source.
|
|
6
|
+
* These options restore fast HMR behaviour.
|
|
7
|
+
*/
|
|
8
|
+
interface TargetHmrConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Rewrite a CSS import in the entry file.
|
|
11
|
+
* Useful when the source CSS contains `@tailwind` directives that would
|
|
12
|
+
* cause Vite to re-run PostCSS on every HMR update.
|
|
13
|
+
*
|
|
14
|
+
* @example { from: './index.css', to: '../dist/app.css' }
|
|
15
|
+
*/
|
|
16
|
+
cssRedirect?: {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Inject `import.meta.hot.accept()` in the entry file.
|
|
22
|
+
* Prevents HMR propagation to the root when the entry re-exports
|
|
23
|
+
* mixed values (components + config objects).
|
|
24
|
+
*/
|
|
25
|
+
entryBoundary?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Full unlock target configuration.
|
|
29
|
+
*/
|
|
30
|
+
interface UnlockTarget {
|
|
31
|
+
/** npm package name to unlock (e.g. "@acme/dashboard") */
|
|
32
|
+
package: string;
|
|
33
|
+
/** Import alias for the package source (e.g. "~dashboard") -- auto-generated if omitted */
|
|
34
|
+
alias?: string;
|
|
35
|
+
/** Subdirectory within the package that contains source files (default: "src") */
|
|
36
|
+
srcDir?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Entry redirect: remap dist entry to source entry.
|
|
39
|
+
* e.g. { from: "dist/app.mjs", to: "src/app.tsx" }
|
|
40
|
+
*/
|
|
41
|
+
entryRedirect?: {
|
|
42
|
+
from: string;
|
|
43
|
+
to: string;
|
|
44
|
+
};
|
|
45
|
+
/** HMR optimizations for the unbundled target */
|
|
46
|
+
hmr?: TargetHmrConfig;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shorthand: a string is expanded to `{ package: theString }`.
|
|
50
|
+
*/
|
|
51
|
+
type UnlockTargetInput = string | UnlockTarget;
|
|
52
|
+
/**
|
|
53
|
+
* Match strategy for resolving overrides.
|
|
54
|
+
* - "basename": match by filename only (default)
|
|
55
|
+
* - "path": match by relative path
|
|
56
|
+
*/
|
|
57
|
+
type MatchStrategy = "basename" | "path";
|
|
58
|
+
/**
|
|
59
|
+
* Conflict resolution strategy when multiple targets have the same filename.
|
|
60
|
+
* - "error": throw an error (default)
|
|
61
|
+
* - "warn": log a warning and use first match
|
|
62
|
+
* - "first": silently use first match
|
|
63
|
+
*/
|
|
64
|
+
type ConflictStrategy = "error" | "warn" | "first";
|
|
65
|
+
/**
|
|
66
|
+
* Patch configuration: modify a target file using a config file.
|
|
67
|
+
*/
|
|
68
|
+
interface PatchConfig {
|
|
69
|
+
/** Pattern to match target file paths */
|
|
70
|
+
target: RegExp;
|
|
71
|
+
/** Config file basename to search in override dirs (without extension) */
|
|
72
|
+
configFile: string;
|
|
73
|
+
/** Transform function: receives original code + absolute config path, returns patched code */
|
|
74
|
+
apply(code: string, configPath: string): string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Plugin options.
|
|
78
|
+
*/
|
|
79
|
+
interface UnlockOptions {
|
|
80
|
+
/** Packages to unlock */
|
|
81
|
+
targets: UnlockTargetInput[];
|
|
82
|
+
/** Directory containing override files (default: "./src/overrides") */
|
|
83
|
+
overrides?: string | string[];
|
|
84
|
+
/** Match strategy (default: "basename") */
|
|
85
|
+
match?: MatchStrategy;
|
|
86
|
+
/** Conflict handling when basename collides across targets (default: "error") */
|
|
87
|
+
onConflict?: ConflictStrategy;
|
|
88
|
+
/** Enable debug logging (default: false) */
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
/** File extensions to consider (default: standard web extensions) */
|
|
91
|
+
extensions?: string[];
|
|
92
|
+
/** Patches: modify target files using config files from override dirs */
|
|
93
|
+
patches?: PatchConfig[];
|
|
94
|
+
/**
|
|
95
|
+
* Content patterns that trigger HMR boundary injection.
|
|
96
|
+
* If a file's code contains any of these strings, `import.meta.hot.accept()`
|
|
97
|
+
* is appended. Useful for mixed-export modules (component + config) that
|
|
98
|
+
* React Fast Refresh can't self-accept.
|
|
99
|
+
*
|
|
100
|
+
* @example ["defineRouteConfig", "defineWidgetConfig"]
|
|
101
|
+
*/
|
|
102
|
+
hmrBoundaries?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type { ConflictStrategy as C, MatchStrategy as M, PatchConfig as P, TargetHmrConfig as T, UnlockOptions as U, UnlockTarget as a, UnlockTargetInput as b };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMR configuration for an unbundled target.
|
|
3
|
+
*
|
|
4
|
+
* When a package is excluded from pre-bundling (optimizeDeps.exclude),
|
|
5
|
+
* Vite loses the pre-bundled HMR boundary and processes raw source.
|
|
6
|
+
* These options restore fast HMR behaviour.
|
|
7
|
+
*/
|
|
8
|
+
interface TargetHmrConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Rewrite a CSS import in the entry file.
|
|
11
|
+
* Useful when the source CSS contains `@tailwind` directives that would
|
|
12
|
+
* cause Vite to re-run PostCSS on every HMR update.
|
|
13
|
+
*
|
|
14
|
+
* @example { from: './index.css', to: '../dist/app.css' }
|
|
15
|
+
*/
|
|
16
|
+
cssRedirect?: {
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Inject `import.meta.hot.accept()` in the entry file.
|
|
22
|
+
* Prevents HMR propagation to the root when the entry re-exports
|
|
23
|
+
* mixed values (components + config objects).
|
|
24
|
+
*/
|
|
25
|
+
entryBoundary?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Full unlock target configuration.
|
|
29
|
+
*/
|
|
30
|
+
interface UnlockTarget {
|
|
31
|
+
/** npm package name to unlock (e.g. "@acme/dashboard") */
|
|
32
|
+
package: string;
|
|
33
|
+
/** Import alias for the package source (e.g. "~dashboard") -- auto-generated if omitted */
|
|
34
|
+
alias?: string;
|
|
35
|
+
/** Subdirectory within the package that contains source files (default: "src") */
|
|
36
|
+
srcDir?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Entry redirect: remap dist entry to source entry.
|
|
39
|
+
* e.g. { from: "dist/app.mjs", to: "src/app.tsx" }
|
|
40
|
+
*/
|
|
41
|
+
entryRedirect?: {
|
|
42
|
+
from: string;
|
|
43
|
+
to: string;
|
|
44
|
+
};
|
|
45
|
+
/** HMR optimizations for the unbundled target */
|
|
46
|
+
hmr?: TargetHmrConfig;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shorthand: a string is expanded to `{ package: theString }`.
|
|
50
|
+
*/
|
|
51
|
+
type UnlockTargetInput = string | UnlockTarget;
|
|
52
|
+
/**
|
|
53
|
+
* Match strategy for resolving overrides.
|
|
54
|
+
* - "basename": match by filename only (default)
|
|
55
|
+
* - "path": match by relative path
|
|
56
|
+
*/
|
|
57
|
+
type MatchStrategy = "basename" | "path";
|
|
58
|
+
/**
|
|
59
|
+
* Conflict resolution strategy when multiple targets have the same filename.
|
|
60
|
+
* - "error": throw an error (default)
|
|
61
|
+
* - "warn": log a warning and use first match
|
|
62
|
+
* - "first": silently use first match
|
|
63
|
+
*/
|
|
64
|
+
type ConflictStrategy = "error" | "warn" | "first";
|
|
65
|
+
/**
|
|
66
|
+
* Patch configuration: modify a target file using a config file.
|
|
67
|
+
*/
|
|
68
|
+
interface PatchConfig {
|
|
69
|
+
/** Pattern to match target file paths */
|
|
70
|
+
target: RegExp;
|
|
71
|
+
/** Config file basename to search in override dirs (without extension) */
|
|
72
|
+
configFile: string;
|
|
73
|
+
/** Transform function: receives original code + absolute config path, returns patched code */
|
|
74
|
+
apply(code: string, configPath: string): string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Plugin options.
|
|
78
|
+
*/
|
|
79
|
+
interface UnlockOptions {
|
|
80
|
+
/** Packages to unlock */
|
|
81
|
+
targets: UnlockTargetInput[];
|
|
82
|
+
/** Directory containing override files (default: "./src/overrides") */
|
|
83
|
+
overrides?: string | string[];
|
|
84
|
+
/** Match strategy (default: "basename") */
|
|
85
|
+
match?: MatchStrategy;
|
|
86
|
+
/** Conflict handling when basename collides across targets (default: "error") */
|
|
87
|
+
onConflict?: ConflictStrategy;
|
|
88
|
+
/** Enable debug logging (default: false) */
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
/** File extensions to consider (default: standard web extensions) */
|
|
91
|
+
extensions?: string[];
|
|
92
|
+
/** Patches: modify target files using config files from override dirs */
|
|
93
|
+
patches?: PatchConfig[];
|
|
94
|
+
/**
|
|
95
|
+
* Content patterns that trigger HMR boundary injection.
|
|
96
|
+
* If a file's code contains any of these strings, `import.meta.hot.accept()`
|
|
97
|
+
* is appended. Useful for mixed-export modules (component + config) that
|
|
98
|
+
* React Fast Refresh can't self-accept.
|
|
99
|
+
*
|
|
100
|
+
* @example ["defineRouteConfig", "defineWidgetConfig"]
|
|
101
|
+
*/
|
|
102
|
+
hmrBoundaries?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type { ConflictStrategy as C, MatchStrategy as M, PatchConfig as P, TargetHmrConfig as T, UnlockOptions as U, UnlockTarget as a, UnlockTargetInput as b };
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unlockable/vite-plugin-unlock",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal Vite plugin to unlock and override any module from any npm package by filename convention",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./medusa": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/medusa.d.ts",
|
|
23
|
+
"default": "./dist/medusa.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/medusa.d.cts",
|
|
27
|
+
"default": "./dist/medusa.cjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"prepublishOnly": "yarn build"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"vite",
|
|
42
|
+
"vite-plugin",
|
|
43
|
+
"unlock",
|
|
44
|
+
"override",
|
|
45
|
+
"module-override",
|
|
46
|
+
"component-override",
|
|
47
|
+
"theming",
|
|
48
|
+
"customization",
|
|
49
|
+
"unlockable",
|
|
50
|
+
"medusa"
|
|
51
|
+
],
|
|
52
|
+
"author": {
|
|
53
|
+
"name": "Olivier Belaud",
|
|
54
|
+
"url": "https://olivierbelaud.dev"
|
|
55
|
+
},
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"homepage": "https://github.com/unlockablejs/vite-plugin-unlock#readme",
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/unlockablejs/vite-plugin-unlock.git"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/unlockablejs/vite-plugin-unlock/issues"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"vite": ">=5.0.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/node": "^22.0.0",
|
|
73
|
+
"tsup": "^8.4.0",
|
|
74
|
+
"typescript": "^5.7.0",
|
|
75
|
+
"vite": "^6.0.0"
|
|
76
|
+
}
|
|
77
|
+
}
|