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