ember-vite-hmr 0.2.0 → 0.4.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/dist/lib/hmr.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export default function (resolver: any): {
1
+ export declare function hmr(): {
2
2
  name: string;
3
3
  enforce: string;
4
4
  transform(source: any, id: any): any;
package/dist/lib/hmr.js CHANGED
@@ -1,42 +1,51 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function transform({ resolver, resourcePath, plugin }) {
4
- const resourcePath = resourcePath.replace(/\\/g, '/').split('?')[0];
5
- const supportedPaths = ['routers', 'controllers', 'routes'];
6
- const supportedFileNames = [
7
- 'router.js',
8
- 'router.ts',
9
- 'router.gts',
10
- 'router.gjs',
11
- 'controller.js',
12
- 'controller.ts',
13
- ];
14
- if (resourcePath.endsWith('.hbs') ||
15
- resourcePath.endsWith('.gjs') ||
16
- resourcePath.endsWith('.gts')) {
17
- const result = [...source.matchAll(/import.meta.hot.accept\(\'([^']+)\'/g)];
18
- for (const resultElement of result) {
19
- const dep = resultElement[1];
20
- const resolved = await resolver.resolveId.call(plugin, dep, resourcePath, {});
21
- let id = resolved.id;
22
- if (id.includes('rewritten-app')) {
23
- id = id.split('rewritten-app')[1];
24
- }
25
- if (path.resolve(id).replace(/\\/g, '/') === id && path.isAbsolute(id)) {
26
- if (!id.startsWith('/')) {
27
- id = '/' + id;
6
+ exports.hmr = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ function hmr() {
9
+ return {
10
+ name: 'hmr-plugin',
11
+ enforce: 'post',
12
+ transform(source, id) {
13
+ const resourcePath = id.replace(/\\/g, '/').split('?')[0];
14
+ const supportedPaths = ['routers', 'controllers', 'routes'];
15
+ const supportedFileNames = [
16
+ 'router.js',
17
+ 'router.ts',
18
+ 'router.gts',
19
+ 'router.gjs',
20
+ 'controller.js',
21
+ 'controller.ts',
22
+ ];
23
+ if (resourcePath.endsWith('.hbs') ||
24
+ resourcePath.endsWith('.gjs') ||
25
+ resourcePath.endsWith('.gts')) {
26
+ const result = [...source.matchAll(/import.meta.hot.accept\(\'([^']+)\'/g)];
27
+ for (const resultElement of result) {
28
+ const dep = resultElement[1];
29
+ const resolved = await this.resolve(dep, resourcePath, {});
30
+ let id = resolved.id;
31
+ if (id.includes('rewritten-app')) {
32
+ id = id.split('rewritten-app')[1];
33
+ }
34
+ if (path_1.default.resolve(id).replace(/\\/g, '/') === id && path_1.default.isAbsolute(id)) {
35
+ if (!id.startsWith('/')) {
36
+ id = '/' + id;
37
+ }
38
+ id = '/@fs' + id;
39
+ }
40
+ source = source.replace(`import.meta.hot.accept('${dep}'`, `import.meta.hot.accept('${id}'`);
28
41
  }
29
- id = '/@fs' + id;
42
+ return source;
30
43
  }
31
- source = source.replace(`import.meta.hot.accept('${dep}'`, `import.meta.hot.accept('${id}'`);
32
- }
33
- return source;
34
- }
35
- if (!supportedPaths.some((s) => resourcePath.includes(`/${s}/`)) &&
36
- !supportedFileNames.some((s) => resourcePath.endsWith(s))) {
37
- return source;
38
- }
39
- return `${source}
44
+ if (!supportedPaths.some((s) => resourcePath.includes(`/${s}/`)) &&
45
+ !supportedFileNames.some((s) => resourcePath.endsWith(s))) {
46
+ return source;
47
+ }
48
+ return `${source}
40
49
  if (import.meta.hot && window.emberHotReloadPlugin) {
41
50
  const result = window.emberHotReloadPlugin.canAcceptNew(import.meta.url);
42
51
  result.then(() => {
@@ -48,20 +57,7 @@ function transform({ resolver, resourcePath, plugin }) {
48
57
  });
49
58
  }
50
59
  `;
51
- }
52
- function default_1(resolver) {
53
- return {
54
- name: 'hmr-plugin',
55
- enforce: 'post',
56
- transform(source, id) {
57
- const options = {
58
- resolver,
59
- plugin: this,
60
- source,
61
- resourcePath: id,
62
- };
63
- return transform.call(options);
64
60
  },
65
61
  };
66
62
  }
67
- exports.default = default_1;
63
+ exports.hmr = hmr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-vite-hmr",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "keywords": [
5
5
  "ember-addon"
6
6
  ],
@@ -126,7 +126,7 @@
126
126
  },
127
127
  "exports": {
128
128
  ".": {
129
- "default": "./dist/lib/ember-webpack.js"
129
+ "default": "./dist/lib/hmr.js"
130
130
  },
131
131
  "./*": {
132
132
  "types": "./declarations/*.d.ts",