vite-plugin-solid 2.1.1 → 2.2.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/README.md CHANGED
@@ -1,186 +1,181 @@
1
- # ⚡ vite-plugin-solid
2
-
3
- A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
4
-
5
- <img alt="HMR gif demonstrationdemodemodemo" src=".github/hmr.gif">
6
-
7
- # Got a question? / Need help?
8
-
9
- Join [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.
10
-
11
- ## Features
12
-
13
- - HMR with no configuration needed
14
- - Drop-in installation as a vite plugin
15
- - Minimal bundle size
16
- - Support typescript (`.tsx`) out of the box
17
- - Support code splitting out of the box
18
-
19
- ## Requirements
20
-
21
- This module 100% esm compatible. As per [this document](https://nodejs.org/api/esm.html) it is strongly recommended to have at least the version `14.13.0` of node installed.
22
-
23
- You can check your current version of node by typing `node -v` in your terminal. If your version is below that one version I'd encourage you to either do an update globally or use a node version management tool such as [volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm).
24
-
25
- ## Quickstart
26
-
27
- You can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:
28
-
29
- ```bash
30
- $ npx degit solidjs/templates/js my-solid-project
31
- $ cd my-solid-project
32
- $ npm install # or pnpm install or yarn install
33
- $ npm run start # starts dev-server with hot-module-reloading
34
- $ npm run build # builds to /dist
35
- ```
36
-
37
- ## Installation
38
-
39
- Install `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.
40
-
41
- Install `solid-js` as dependency.
42
-
43
- You have to install those so that you are in control to which solid version is used to compile your code.
44
-
45
- ```bash
46
- # with npm
47
- $ npm install -D vite vite-plugin-solid babel-preset-solid
48
- $ npm install solid-js
49
-
50
- # with pnpm
51
- $ pnpm add -D vite vite-plugin-solid babel-preset-solid
52
- $ pnpm add solid-js
53
-
54
- # with yarn
55
- $ yarn add -D vite vite-plugin-solid babel-preset-solid
56
- $ yarn add solid-js
57
- ```
58
-
59
- Add it as plugin to `vite.config.js`
60
-
61
- ```js
62
- // vite.config.ts
63
- import { defineConfig } from 'vite';
64
- import solidPlugin from 'vite-plugin-solid';
65
-
66
- export default defineConfig({
67
- plugins: [solidPlugin()],
68
- });
69
- ```
70
-
71
- ## Run
72
-
73
- Just use regular `vite` or `vite build` commands
74
-
75
- ```json
76
- {
77
- "scripts": {
78
- "dev": "vite",
79
- "build": "vite build"
80
- }
81
- }
82
- ```
83
-
84
- ## API
85
-
86
- ### options
87
-
88
- - Type: Object
89
- - Default: {}
90
-
91
- #### options.dev
92
-
93
- - Type: Boolean
94
- - Default: true
95
-
96
- This will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.
97
- If set to false, it won't inject it in dev.
98
- This is useful for extra logs and debug.
99
-
100
- #### options.hmr
101
-
102
- - Type: Boolean
103
- - Default: true
104
-
105
- This will inject HMR runtime in dev mode. Has no effect in prod.
106
- If set to false, it won't inject the runtime in dev.
107
-
108
- #### options.ssr
109
-
110
- - Type: Boolean
111
- - Default: false
112
-
113
- This will force SSR code in the produced files. This is experiemental and mostly not working yet.
114
-
115
- #### options.babel
116
-
117
- - Type: Babel.TransformOptions
118
- - Default: {}
119
-
120
- Pass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.
121
-
122
- #### options.solid
123
-
124
- - Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)
125
- - Default: {}
126
-
127
- Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
128
- They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
129
-
130
- #### options.typescript
131
-
132
- - Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
133
- - Default: {}
134
-
135
- Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
136
-
137
- ## Note on HMR
138
-
139
- Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
140
-
141
- At this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:
142
-
143
- - Every component that you expect to have HMR should be exported as default eg:
144
-
145
- ```tsx
146
- const MyComponent = () => <h1>My component</h1>;
147
- export default MyComponent;
148
- ```
149
-
150
- - When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.
151
-
152
- - The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.
153
-
154
- - Currently there's a parsing issue if you export default on the same line as declaration like so: `export default function App() {...}`. It should be made in two steps. First declare then export, similar to the example in the first bullet point.
155
-
156
- If at least one of this point is blocking to you, you can revert to the old behavior but [opting out the automatic HMR](#options) and placing the following snippet in your entry point:
157
-
158
- ```jsx
159
- const dispose = render(() => <App />, document.body);
160
-
161
- if (import.meta.hot) {
162
- import.meta.hmr.accept();
163
- import.meta.hmr.dispose(dispose);
164
- }
165
- ```
166
-
167
- # Troubleshooting
168
-
169
- - It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow [this thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000154544-I-m-having-a-huge-problem-with-Webstorm-and-react-hot-loader-) and disable the **"Safe Write"** option in **"Settings | Appearance & Behavior | System Settings"**.
170
-
171
- - If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the [dependencies optimization](https://vitejs.dev/config/#optimizedeps-exclude)
172
-
173
- - If you are trying to make [directives](https://www.solidjs.com/docs/latest/api#use%3A___) work and they somehow don't try setting the `options.typescript.onlyRemoveTypeImports` option to `true`
174
-
175
- ## Migration from v1
176
-
177
- The master branch now target vite 2.
178
-
179
- The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
180
-
181
- For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
182
-
183
- # Credits
184
-
185
- - [solid-js](https://github.com/solidjs/solid)
186
- - [vite](https://github.com/vitejs/vite)
1
+ <p>
2
+ <img width="100%" src="https://raw.githubusercontent.com/solidjs/vite-plugin-solid/master/banner.png" alt="Solid Vite Plugin">
3
+ </p>
4
+
5
+ # vite-plugin-solid
6
+
7
+ A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
8
+
9
+ <img alt="HMR gif demonstrationdemodemodemo" src=".github/hmr.gif">
10
+
11
+ # Got a question? / Need help?
12
+
13
+ Join [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.
14
+
15
+ ## Features
16
+
17
+ - HMR with no configuration needed
18
+ - Drop-in installation as a vite plugin
19
+ - Minimal bundle size
20
+ - Support typescript (`.tsx`) out of the box
21
+ - Support code splitting out of the box
22
+
23
+ ## Requirements
24
+
25
+ This module 100% esm compatible. As per [this document](https://nodejs.org/api/esm.html) it is strongly recommended to have at least the version `14.13.0` of node installed.
26
+
27
+ You can check your current version of node by typing `node -v` in your terminal. If your version is below that one version I'd encourage you to either do an update globally or use a node version management tool such as [volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm).
28
+
29
+ ## Quickstart
30
+
31
+ You can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:
32
+
33
+ ```bash
34
+ $ npx degit solidjs/templates/js my-solid-project
35
+ $ cd my-solid-project
36
+ $ npm install # or pnpm install or yarn install
37
+ $ npm run start # starts dev-server with hot-module-reloading
38
+ $ npm run build # builds to /dist
39
+ ```
40
+
41
+ ## Installation
42
+
43
+ Install `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.
44
+
45
+ Install `solid-js` as dependency.
46
+
47
+ You have to install those so that you are in control to which solid version is used to compile your code.
48
+
49
+ ```bash
50
+ # with npm
51
+ $ npm install -D vite vite-plugin-solid babel-preset-solid
52
+ $ npm install solid-js
53
+
54
+ # with pnpm
55
+ $ pnpm add -D vite vite-plugin-solid babel-preset-solid
56
+ $ pnpm add solid-js
57
+
58
+ # with yarn
59
+ $ yarn add -D vite vite-plugin-solid babel-preset-solid
60
+ $ yarn add solid-js
61
+ ```
62
+
63
+ Add it as plugin to `vite.config.js`
64
+
65
+ ```js
66
+ // vite.config.ts
67
+ import { defineConfig } from 'vite';
68
+ import solidPlugin from 'vite-plugin-solid';
69
+
70
+ export default defineConfig({
71
+ plugins: [solidPlugin()],
72
+ });
73
+ ```
74
+
75
+ ## Run
76
+
77
+ Just use regular `vite` or `vite build` commands
78
+
79
+ ```json
80
+ {
81
+ "scripts": {
82
+ "dev": "vite",
83
+ "build": "vite build"
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## API
89
+
90
+ ### options
91
+
92
+ - Type: Object
93
+ - Default: {}
94
+
95
+ #### options.dev
96
+
97
+ - Type: Boolean
98
+ - Default: true
99
+
100
+ This will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.
101
+ If set to false, it won't inject it in dev.
102
+ This is useful for extra logs and debug.
103
+
104
+ #### options.hot
105
+
106
+ - Type: Boolean
107
+ - Default: true
108
+
109
+ This will inject HMR runtime in dev mode. Has no effect in prod.
110
+ If set to false, it won't inject the runtime in dev.
111
+
112
+ #### options.ssr
113
+
114
+ - Type: Boolean
115
+ - Default: false
116
+
117
+ This will force SSR code in the produced files. This is experiemental and mostly not working yet.
118
+
119
+ #### options.babel
120
+
121
+ - Type: Babel.TransformOptions
122
+ - Default: {}
123
+
124
+ Pass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.
125
+
126
+ #### options.solid
127
+
128
+ - Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)
129
+ - Default: {}
130
+
131
+ Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
132
+ They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
133
+
134
+ #### options.typescript
135
+
136
+ - Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
137
+ - Default: {}
138
+
139
+ Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
140
+
141
+ ## Note on HMR
142
+
143
+ Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
144
+
145
+ At this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:
146
+
147
+ - When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.
148
+
149
+ - The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.
150
+
151
+ If at least one of this point is blocking to you, you can revert to the old behavior but [opting out the automatic HMR](#options) and placing the following snippet in your entry point:
152
+
153
+ ```jsx
154
+ const dispose = render(() => <App />, document.body);
155
+
156
+ if (import.meta.hot) {
157
+ import.meta.hot.accept();
158
+ import.meta.hot.dispose(dispose);
159
+ }
160
+ ```
161
+
162
+ # Troubleshooting
163
+
164
+ - It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow [this thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000154544-I-m-having-a-huge-problem-with-Webstorm-and-react-hot-loader-) and disable the **"Safe Write"** option in **"Settings | Appearance & Behavior | System Settings"**.
165
+
166
+ - If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the [dependencies optimization](https://vitejs.dev/config/#optimizedeps-exclude)
167
+
168
+ - If you are trying to make [directives](https://www.solidjs.com/docs/latest/api#use%3A___) work and they somehow don't try setting the `options.typescript.onlyRemoveTypeImports` option to `true`
169
+
170
+ ## Migration from v1
171
+
172
+ The master branch now target vite 2.
173
+
174
+ The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
175
+
176
+ For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
177
+
178
+ # Credits
179
+
180
+ - [solid-js](https://github.com/solidjs/solid)
181
+ - [vite](https://github.com/vitejs/vite)
@@ -21,10 +21,17 @@ const runtimePublicPath = '/@solid-refresh';
21
21
  const runtimeFilePath = require$1.resolve('solid-refresh/dist/solid-refresh.mjs');
22
22
 
23
23
  const runtimeCode = fs.readFileSync(runtimeFilePath, 'utf-8');
24
- /** Configuration options for vite-plugin-solid. */
24
+ /** Possible options for the extensions property */
25
+
26
+ function getExtension(filename) {
27
+ const index = filename.lastIndexOf('.');
28
+ return index < 0 ? '' : filename.substring(index);
29
+ }
25
30
 
26
31
  function solidPlugin(options = {}) {
27
32
  let needHmr = false;
33
+ let replaceDev = false;
34
+ let projectRoot = process.cwd();
28
35
  return {
29
36
  name: 'solid',
30
37
  enforce: 'pre',
@@ -32,19 +39,19 @@ function solidPlugin(options = {}) {
32
39
  config(userConfig, {
33
40
  command
34
41
  }) {
35
- var _userConfig$resolve;
36
-
37
42
  // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
38
- const replaceDev = options.dev === true || options.dev !== false && command === 'serve'; // TODO: remove when fully removed from vite
43
+ replaceDev = options.dev === true || options.dev !== false && command === 'serve';
44
+ projectRoot = userConfig.root; // TODO: remove when fully removed from vite
39
45
 
40
46
  const legacyAlias = normalizeAliases(userConfig.alias);
41
47
  if (!userConfig.resolve) userConfig.resolve = {};
42
- userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases((_userConfig$resolve = userConfig.resolve) === null || _userConfig$resolve === void 0 ? void 0 : _userConfig$resolve.alias)];
43
- const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];
48
+ userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)]; // fix for bundling dev in production
49
+
50
+ const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
44
51
  return {
45
- /**
46
- * We only need esbuild on .ts or .js files.
47
- * .tsx & .jsx files are handled by us
52
+ /**
53
+ * We only need esbuild on .ts or .js files.
54
+ * .tsx & .jsx files are handled by us
48
55
  */
49
56
  esbuild: {
50
57
  include: /\.ts$/
@@ -76,14 +83,21 @@ function solidPlugin(options = {}) {
76
83
  },
77
84
 
78
85
  async transform(source, id, transformOptions) {
79
- // @ts-expect-error anticipate vite changing second parameter as options object
80
- // see https://github.com/vitejs/vite/discussions/5109
81
- const ssr = transformOptions === true || (transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.ssr);
82
- if (!/\.[jt]sx/.test(id)) return null;
86
+ const isSsr = transformOptions?.ssr;
87
+ const currentFileExtension = getExtension(id);
88
+ const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];
89
+ const allCustomExtensions = extensionsToWatch.map(extension => // An extension can be a string or a tuple [extension, options]
90
+ typeof extension === 'string' ? extension : extension[0]);
91
+
92
+ if (!allCustomExtensions.includes(currentFileExtension)) {
93
+ return null;
94
+ }
95
+
96
+ const inNodeModules = /node_modules/.test(id);
83
97
  let solidOptions;
84
98
 
85
99
  if (options.ssr) {
86
- if (ssr) {
100
+ if (isSsr) {
87
101
  solidOptions = {
88
102
  generate: 'ssr',
89
103
  hydratable: true
@@ -102,16 +116,33 @@ function solidPlugin(options = {}) {
102
116
  }
103
117
 
104
118
  const opts = {
119
+ babelrc: false,
120
+ configFile: false,
121
+ root: projectRoot,
105
122
  filename: id,
123
+ sourceFileName: id,
106
124
  presets: [[solid__default["default"], { ...solidOptions,
107
125
  ...(options.solid || {})
108
126
  }]],
109
- plugins: needHmr ? [[solidRefresh__default["default"], {
127
+ plugins: needHmr && !inNodeModules ? [[solidRefresh__default["default"], {
110
128
  bundler: 'vite'
111
- }]] : []
112
- };
129
+ }]] : [],
130
+ sourceMaps: true,
131
+ // Vite handles sourcemap flattening
132
+ inputSourceMap: false
133
+ }; // We need to know if the current file extension has a typescript options tied to it
134
+
135
+ const shouldBeProcessedWithTypescript = extensionsToWatch.some(extension => {
136
+ if (typeof extension === 'string') {
137
+ return extension.includes('tsx');
138
+ }
139
+
140
+ const [extensionName, extensionOptions] = extension;
141
+ if (extensionName !== currentFileExtension) return false;
142
+ return extensionOptions.typescript;
143
+ });
113
144
 
114
- if (id.includes('tsx')) {
145
+ if (shouldBeProcessedWithTypescript) {
115
146
  opts.presets.push([ts__default["default"], options.typescript || {}]);
116
147
  } // Default value for babel user options
117
148
 
@@ -120,7 +151,7 @@ function solidPlugin(options = {}) {
120
151
 
121
152
  if (options.babel) {
122
153
  if (typeof options.babel === 'function') {
123
- const babelOptions = options.babel(source, id, ssr);
154
+ const babelOptions = options.babel(source, id, isSsr);
124
155
  babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;
125
156
  } else {
126
157
  babelUserOptions = options.babel;
@@ -140,11 +171,11 @@ function solidPlugin(options = {}) {
140
171
 
141
172
  };
142
173
  }
143
- /**
144
- * This basically normalize all aliases of the config into
145
- * the array format of the alias.
146
- *
147
- * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
174
+ /**
175
+ * This basically normalize all aliases of the config into
176
+ * the array format of the alias.
177
+ *
178
+ * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
148
179
  */
149
180
 
150
181
  function normalizeAliases(alias = []) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\r\nimport ts from '@babel/preset-typescript';\r\nimport solid from 'babel-preset-solid';\r\nimport { readFileSync } from 'fs';\r\nimport { mergeAndConcat } from 'merge-anything';\r\nimport { createRequire } from 'module';\r\nimport solidRefresh from 'solid-refresh/babel.js';\r\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\r\n\r\nconst require = createRequire(import.meta.url);\r\n\r\nconst runtimePublicPath = '/@solid-refresh';\r\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\r\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\r\n\r\n/** Configuration options for vite-plugin-solid. */\r\nexport interface Options {\r\n /**\r\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\r\n * effect in prod. If set to `false`, it won't inject it in dev. This is\r\n * useful for extra logs and debugging.\r\n *\r\n * @default true\r\n */\r\n dev: boolean;\r\n /**\r\n * This will force SSR code in the produced files. This is experiemental\r\n * and mostly not working yet.\r\n *\r\n * @default false\r\n */\r\n ssr: boolean;\r\n /**\r\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\r\n * set to `false`, it won't inject the runtime in dev.\r\n *\r\n * @default true\r\n */\r\n hot: boolean;\r\n /**\r\n * Pass any additional babel transform options. They will be merged with\r\n * the transformations required by Solid.\r\n *\r\n * @default {}\r\n */\r\n babel:\r\n | TransformOptions\r\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\r\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\r\n typescript: {\r\n /**\r\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\r\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\r\n * true requires allExtensions: true.\r\n *\r\n * @default false\r\n */\r\n isTSX?: boolean;\r\n\r\n /**\r\n * Replace the function used when compiling JSX expressions. This is so that\r\n * we know that the import is not a type import, and should not be removed.\r\n *\r\n * @default React\r\n */\r\n jsxPragma?: string;\r\n\r\n /**\r\n * Replace the function used when compiling JSX fragment expressions. This\r\n * is so that we know that the import is not a type import, and should not\r\n * be removed.\r\n *\r\n * @default React.Fragment\r\n */\r\n jsxPragmaFrag?: string;\r\n\r\n /**\r\n * Indicates that every file should be parsed as TS or TSX (depending on the\r\n * isTSX option).\r\n *\r\n * @default false\r\n */\r\n allExtensions?: boolean;\r\n\r\n /**\r\n * Enables compilation of TypeScript namespaces.\r\n *\r\n * @default uses the default set by @babel/plugin-transform-typescript.\r\n */\r\n allowNamespaces?: boolean;\r\n\r\n /**\r\n * When enabled, type-only class fields are only removed if they are\r\n * prefixed with the declare modifier:\r\n *\r\n * > NOTE: This will be enabled by default in Babel 8\r\n *\r\n * @default false\r\n *\r\n * @example\r\n * ```ts\r\n * class A {\r\n * declare foo: string; // Removed\r\n * bar: string; // Initialized to undefined\r\n * prop?: string; // Initialized to undefined\r\n * prop1!: string // Initialized to undefined\r\n * }\r\n * ```\r\n */\r\n allowDeclareFields?: boolean;\r\n\r\n /**\r\n * When set to true, the transform will only remove type-only imports\r\n * (introduced in TypeScript 3.8). This should only be used if you are using\r\n * TypeScript >= 3.8.\r\n *\r\n * @default false\r\n */\r\n onlyRemoveTypeImports?: boolean;\r\n\r\n /**\r\n * When set to true, Babel will inline enum values rather than using the\r\n * usual enum output:\r\n *\r\n * This option differs from TypeScript's --isolatedModules behavior, which\r\n * ignores the const modifier and compiles them as normal enums, and aligns\r\n * Babel's behavior with TypeScript's default behavior.\r\n *\r\n * ```ts\r\n * // Input\r\n * const enum Animals {\r\n * Fish\r\n * }\r\n * console.log(Animals.Fish);\r\n *\r\n * // Default output\r\n * var Animals;\r\n *\r\n * (function (Animals) {\r\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\r\n * })(Animals || (Animals = {}));\r\n *\r\n * console.log(Animals.Fish);\r\n *\r\n * // `optimizeConstEnums` output\r\n * console.log(0);\r\n * ```\r\n *\r\n * However, when exporting a const enum Babel will compile it to a plain\r\n * object literal so that it doesn't need to rely on cross-file analysis\r\n * when compiling it:\r\n *\r\n * ```ts\r\n * // Input\r\n * export const enum Animals {\r\n * Fish,\r\n * }\r\n *\r\n * // `optimizeConstEnums` output\r\n * export var Animals = {\r\n * Fish: 0,\r\n * };\r\n * ```\r\n *\r\n * @default false\r\n */\r\n optimizeConstEnums?: boolean;\r\n };\r\n /**\r\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\r\n * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).\r\n *\r\n * @default {}\r\n */\r\n solid: {\r\n /**\r\n * The name of the runtime module to import the methods from.\r\n *\r\n * @default \"solid-js/web\"\r\n */\r\n moduleName?: string;\r\n\r\n /**\r\n * The output mode of the compiler.\r\n * Can be:\r\n * - \"dom\" is standard output\r\n * - \"ssr\" is for server side rendering of strings.\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom';\r\n\r\n /**\r\n * Indicate whether the output should contain hydratable markers.\r\n *\r\n * @default false\r\n */\r\n hydratable?: boolean;\r\n\r\n /**\r\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\r\n *\r\n * @default true\r\n */\r\n delegateEvents?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether smart conditional detection should be used.\r\n * This optimizes simple boolean expressions and ternaries in JSX.\r\n *\r\n * @default true\r\n */\r\n wrapConditionals?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether to set current render context on Custom Elements and slots.\r\n * Useful for seemless Context API with Web Components.\r\n *\r\n * @default true\r\n */\r\n contextToCustomElements?: boolean;\r\n\r\n /**\r\n * Array of Component exports from module, that aren't included by default with the library.\r\n * This plugin will automatically import them if it comes across them in the JSX.\r\n *\r\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\r\n */\r\n builtIns?: string[];\r\n };\r\n}\r\n\r\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\r\n let needHmr = false;\r\n\r\n return {\r\n name: 'solid',\r\n enforce: 'pre',\r\n\r\n config(userConfig, { command }): UserConfig {\r\n // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode\r\n const replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\r\n\r\n // TODO: remove when fully removed from vite\r\n const legacyAlias = normalizeAliases(userConfig.alias);\r\n\r\n if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\r\n\r\n const nestedDeps = [\r\n 'solid-js',\r\n 'solid-js/web',\r\n 'solid-js/store',\r\n 'solid-js/html',\r\n 'solid-js/h',\r\n ];\r\n\r\n return {\r\n /**\r\n * We only need esbuild on .ts or .js files.\r\n * .tsx & .jsx files are handled by us\r\n */\r\n esbuild: { include: /\\.ts$/ },\r\n resolve: {\r\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\r\n dedupe: nestedDeps,\r\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\r\n },\r\n optimizeDeps: {\r\n include: nestedDeps,\r\n },\r\n } as UserConfig;\r\n },\r\n\r\n configResolved(config) {\r\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\r\n },\r\n\r\n resolveId(id) {\r\n if (id === runtimePublicPath) return id;\r\n },\r\n\r\n load(id) {\r\n if (id === runtimePublicPath) return runtimeCode;\r\n },\r\n\r\n async transform(source, id, transformOptions) {\r\n // @ts-expect-error anticipate vite changing second parameter as options object\r\n // see https://github.com/vitejs/vite/discussions/5109\r\n const ssr: boolean = transformOptions === true || transformOptions?.ssr;\r\n\r\n if (!/\\.[jt]sx/.test(id)) return null;\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (ssr) {\r\n solidOptions = { generate: 'ssr', hydratable: true };\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: true };\r\n }\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: false };\r\n }\r\n\r\n const opts: TransformOptions = {\r\n filename: id,\r\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\r\n plugins: needHmr ? [[solidRefresh, { bundler: 'vite' }]] : [],\r\n };\r\n\r\n if (id.includes('tsx')) {\r\n opts.presets.push([ts, options.typescript || {}]);\r\n }\r\n\r\n // Default value for babel user options\r\n let babelUserOptions: TransformOptions = {};\r\n\r\n if (options.babel) {\r\n if (typeof options.babel === 'function') {\r\n const babelOptions = options.babel(source, id, ssr);\r\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\r\n } else {\r\n babelUserOptions = options.babel;\r\n }\r\n }\r\n\r\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\r\n\r\n const { code, map } = await transformAsync(source, babelOptions);\r\n\r\n return { code, map };\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * This basically normalize all aliases of the config into\r\n * the array format of the alias.\r\n *\r\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\r\n */\r\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\r\n return Array.isArray(alias)\r\n ? alias\r\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\r\n}\r\n"],"names":["require","createRequire","import","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","solidPlugin","options","needHmr","name","enforce","config","userConfig","command","replaceDev","dev","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","transformOptions","ssr","test","solidOptions","generate","hydratable","opts","filename","presets","solid","plugins","solidRefresh","bundler","includes","push","ts","typescript","babelUserOptions","babel","babelOptions","Promise","mergeAndConcat","code","map","transformAsync","Array","isArray","Object","entries"],"mappings":";;;;;;;;;;;;;;;;AASA,MAAMA,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,eAAY,CAACH,eAAD,EA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BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAO0C,KAAK,CAACC,OAAN,CAAc3C,KAAd,IACHA,KADG,GAEH4C,MAAM,CAACC,OAAP,CAAe7C,KAAf,EAAsBwC,GAAtB,CAA0B,CAAC,CAAClC,IAAD,EAAOC,WAAP,CAAD,MAA0B;AAAED,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\nimport ts from '@babel/preset-typescript';\nimport solid from 'babel-preset-solid';\nimport { readFileSync } from 'fs';\nimport { mergeAndConcat } from 'merge-anything';\nimport { createRequire } from 'module';\nimport solidRefresh from 'solid-refresh/babel.js';\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nconst runtimePublicPath = '/@solid-refresh';\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\n\n/** Possible options for the extensions property */\nexport interface ExtensionOptions {\n typescript?: boolean;\n}\n\n/** Configuration options for vite-plugin-solid. */\nexport interface Options {\n /**\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\n * effect in prod. If set to `false`, it won't inject it in dev. This is\n * useful for extra logs and debugging.\n *\n * @default true\n */\n dev: boolean;\n /**\n * This will force SSR code in the produced files. This is experiemental\n * and mostly not working yet.\n *\n * @default false\n */\n ssr: boolean;\n /**\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\n * set to `false`, it won't inject the runtime in dev.\n *\n * @default true\n */\n hot: boolean;\n /**\n * This registers additional extensions that should be processed by\n * vite-plugin-solid.\n *\n * @default undefined\n */\n extensions?: (string | [string, ExtensionOptions])[];\n /**\n * Pass any additional babel transform options. They will be merged with\n * the transformations required by Solid.\n *\n * @default {}\n */\n babel:\n | TransformOptions\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\n typescript: {\n /**\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\n * true requires allExtensions: true.\n *\n * @default false\n */\n isTSX?: boolean;\n\n /**\n * Replace the function used when compiling JSX expressions. This is so that\n * we know that the import is not a type import, and should not be removed.\n *\n * @default React\n */\n jsxPragma?: string;\n\n /**\n * Replace the function used when compiling JSX fragment expressions. This\n * is so that we know that the import is not a type import, and should not\n * be removed.\n *\n * @default React.Fragment\n */\n jsxPragmaFrag?: string;\n\n /**\n * Indicates that every file should be parsed as TS or TSX (depending on the\n * isTSX option).\n *\n * @default false\n */\n allExtensions?: boolean;\n\n /**\n * Enables compilation of TypeScript namespaces.\n *\n * @default uses the default set by @babel/plugin-transform-typescript.\n */\n allowNamespaces?: boolean;\n\n /**\n * When enabled, type-only class fields are only removed if they are\n * prefixed with the declare modifier:\n *\n * > NOTE: This will be enabled by default in Babel 8\n *\n * @default false\n *\n * @example\n * ```ts\n * class A {\n * declare foo: string; // Removed\n * bar: string; // Initialized to undefined\n * prop?: string; // Initialized to undefined\n * prop1!: string // Initialized to undefined\n * }\n * ```\n */\n allowDeclareFields?: boolean;\n\n /**\n * When set to true, the transform will only remove type-only imports\n * (introduced in TypeScript 3.8). This should only be used if you are using\n * TypeScript >= 3.8.\n *\n * @default false\n */\n onlyRemoveTypeImports?: boolean;\n\n /**\n * When set to true, Babel will inline enum values rather than using the\n * usual enum output:\n *\n * This option differs from TypeScript's --isolatedModules behavior, which\n * ignores the const modifier and compiles them as normal enums, and aligns\n * Babel's behavior with TypeScript's default behavior.\n *\n * ```ts\n * // Input\n * const enum Animals {\n * Fish\n * }\n * console.log(Animals.Fish);\n *\n * // Default output\n * var Animals;\n *\n * (function (Animals) {\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\n * })(Animals || (Animals = {}));\n *\n * console.log(Animals.Fish);\n *\n * // `optimizeConstEnums` output\n * console.log(0);\n * ```\n *\n * However, when exporting a const enum Babel will compile it to a plain\n * object literal so that it doesn't need to rely on cross-file analysis\n * when compiling it:\n *\n * ```ts\n * // Input\n * export const enum Animals {\n * Fish,\n * }\n *\n * // `optimizeConstEnums` output\n * export var Animals = {\n * Fish: 0,\n * };\n * ```\n *\n * @default false\n */\n optimizeConstEnums?: boolean;\n };\n /**\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\n * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).\n *\n * @default {}\n */\n solid: {\n /**\n * The name of the runtime module to import the methods from.\n *\n * @default \"solid-js/web\"\n */\n moduleName?: string;\n\n /**\n * The output mode of the compiler.\n * Can be:\n * - \"dom\" is standard output\n * - \"ssr\" is for server side rendering of strings.\n *\n * @default \"dom\"\n */\n generate?: 'ssr' | 'dom';\n\n /**\n * Indicate whether the output should contain hydratable markers.\n *\n * @default false\n */\n hydratable?: boolean;\n\n /**\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\n *\n * @default true\n */\n delegateEvents?: boolean;\n\n /**\n * Boolean indicates whether smart conditional detection should be used.\n * This optimizes simple boolean expressions and ternaries in JSX.\n *\n * @default true\n */\n wrapConditionals?: boolean;\n\n /**\n * Boolean indicates whether to set current render context on Custom Elements and slots.\n * Useful for seemless Context API with Web Components.\n *\n * @default true\n */\n contextToCustomElements?: boolean;\n\n /**\n * Array of Component exports from module, that aren't included by default with the library.\n * This plugin will automatically import them if it comes across them in the JSX.\n *\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\n */\n builtIns?: string[];\n };\n}\n\nfunction getExtension(filename: string): string {\n const index = filename.lastIndexOf('.');\n return index < 0 ? '' : filename.substring(index);\n}\n\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\n let needHmr = false;\n let replaceDev = false;\n let projectRoot = process.cwd();\n\n return {\n name: 'solid',\n enforce: 'pre',\n\n config(userConfig, { command }): UserConfig {\n // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode\n replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\n projectRoot = userConfig.root;\n\n // TODO: remove when fully removed from vite\n const legacyAlias = normalizeAliases(userConfig.alias);\n\n if (!userConfig.resolve) userConfig.resolve = {};\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\n\n // fix for bundling dev in production\n const nestedDeps = replaceDev\n ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h']\n : [];\n\n return {\n /**\n * We only need esbuild on .ts or .js files.\n * .tsx & .jsx files are handled by us\n */\n esbuild: { include: /\\.ts$/ },\n resolve: {\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\n dedupe: nestedDeps,\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\n },\n optimizeDeps: {\n include: nestedDeps,\n },\n } as UserConfig;\n },\n\n configResolved(config) {\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\n },\n\n resolveId(id) {\n if (id === runtimePublicPath) return id;\n },\n\n load(id) {\n if (id === runtimePublicPath) return runtimeCode;\n },\n\n async transform(source, id, transformOptions) {\n const isSsr = transformOptions?.ssr;\n const currentFileExtension = getExtension(id);\n\n const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];\n const allCustomExtensions = extensionsToWatch.map((extension) =>\n // An extension can be a string or a tuple [extension, options]\n typeof extension === 'string' ? extension : extension[0],\n );\n\n if (!allCustomExtensions.includes(currentFileExtension)) {\n return null;\n }\n\n const inNodeModules = /node_modules/.test(id);\n\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\n\n if (options.ssr) {\n if (isSsr) {\n solidOptions = { generate: 'ssr', hydratable: true };\n } else {\n solidOptions = { generate: 'dom', hydratable: true };\n }\n } else {\n solidOptions = { generate: 'dom', hydratable: false };\n }\n\n const opts: TransformOptions = {\n babelrc: false,\n configFile: false,\n root: projectRoot,\n filename: id,\n sourceFileName: id,\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\n plugins: needHmr && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],\n sourceMaps: true,\n // Vite handles sourcemap flattening\n inputSourceMap: false as any,\n };\n\n // We need to know if the current file extension has a typescript options tied to it\n const shouldBeProcessedWithTypescript = extensionsToWatch.some((extension) => {\n if (typeof extension === 'string') {\n return extension.includes('tsx');\n }\n\n const [extensionName, extensionOptions] = extension;\n if (extensionName !== currentFileExtension) return false;\n\n return extensionOptions.typescript;\n });\n\n if (shouldBeProcessedWithTypescript) {\n opts.presets.push([ts, options.typescript || {}]);\n }\n\n // Default value for babel user options\n let babelUserOptions: TransformOptions = {};\n\n if (options.babel) {\n if (typeof options.babel === 'function') {\n const babelOptions = options.babel(source, id, isSsr);\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\n } else {\n babelUserOptions = options.babel;\n }\n }\n\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\n\n const { code, map } = await transformAsync(source, babelOptions);\n\n return { code, map };\n },\n };\n}\n\n/**\n * This basically normalize all aliases of the config into\n * the array format of the alias.\n *\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\n */\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\n return Array.isArray(alias)\n ? alias\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\n}\n"],"names":["require","createRequire","import","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","getExtension","filename","index","lastIndexOf","substring","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","transformOptions","isSsr","ssr","currentFileExtension","extensionsToWatch","extensions","allCustomExtensions","map","extension","includes","inNodeModules","test","solidOptions","generate","hydratable","opts","babelrc","configFile","sourceFileName","presets","solid","plugins","solidRefresh","bundler","sourceMaps","inputSourceMap","shouldBeProcessedWithTypescript","some","extensionName","extensionOptions","typescript","push","ts","babelUserOptions","babel","babelOptions","Promise","mergeAndConcat","code","transformAsync","Array","isArray","Object","entries"],"mappings":";;;;;;;;;;;;;;;;AASA,MAAMA,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,eAAY,CAACH,eAAD,EAAkB,OAAlB,CAAhC;AAEA;;AAqOA,SAASI,YAAT,CAAsBC,QAAtB,EAAgD;AAC9C,QAAMC,KAAK,GAAGD,QAAQ,CAACE,WAAT,CAAqB,GAArB,CAAd;AACA,SAAOD,KAAK,GAAG,CAAR,GAAY,EAAZ,GAAiBD,QAAQ,CAACG,SAAT,CAAmBF,KAAnB,CAAxB;AACD;;AAEc,SAASG,WAAT,CAAqBC,OAAyB,GAAG,EAAjD,EAA6D;AAC1E,MAAIC,OAAO,GAAG,KAAd;AACA,MAAIC,UAAU,GAAG,KAAjB;AACA,MAAIC,WAAW,GAAGC,OAAO,CAACC,GAAR,EAAlB;AAEA,SAAO;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,OAAO,EAAE,KAFJ;;AAILC,IAAAA,MAAM,CAACC,UAAD,EAAa;AAAEC,MAAAA;AAAF,KAAb,EAAsC;AAC1C;AACAR,MAAAA,UAAU,GAAGF,OAAO,CAACW,GAAR,KAAgB,IAAhB,IAAyBX,OAAO,CAACW,GAAR,KAAgB,KAAhB,IAAyBD,OAAO,KAAK,OAA3E;AACAP,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