Skip to content

Commit 11eb8f2

Browse files
fix: resolve path to templates within the module source (#22)
* fix: resolve path to templates within the module source * test: update test suite
1 parent ab60236 commit 11eb8f2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/module.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path'
1+
import { extname, join } from 'path'
22
import { Module } from '@nuxt/types'
33
import Vue from 'vue'
44

@@ -15,18 +15,22 @@ const websocketModule: Module<ModuleOptions> = function (moduleOptions) {
1515
/* istanbul ignore next */
1616
const options = Object.assign(this.options[CONFIG_KEY] || {}, moduleOptions)
1717

18-
const templatePath = join('src', 'templates')
18+
const webSocketManagerPath = require.resolve('./templates/WebSocketManager')
19+
const pluginPath = require.resolve('./templates/plugin')
1920

2021
this.addTemplate({
21-
src: join(templatePath, 'WebSocketManager.ts'),
22-
fileName: join('nuxt-websocket', 'WebSocketManager.ts'),
22+
src: webSocketManagerPath,
23+
fileName: join(
24+
'nuxt-websocket',
25+
`WebSocketManager${extname(webSocketManagerPath)}`
26+
),
2327
options
2428
})
2529

2630
// Register plugin
2731
this.addPlugin({
28-
src: join(templatePath, 'plugin.ts'),
29-
fileName: join('nuxt-websocket', 'websocket.client.ts'),
32+
src: pluginPath,
33+
fileName: join('nuxt-websocket', `websocket.client${extname(pluginPath)}`),
3034
options
3135
})
3236
};

test/module.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ describe('module', () => {
1212

1313
test('should register the plugin', () => {
1414
expectModuleToBeCalledWith('addPlugin', {
15-
src: 'src/templates/plugin.ts',
15+
src: require.resolve('../src/templates/plugin.ts'),
1616
fileName: 'nuxt-websocket/websocket.client.ts',
1717
options: getNuxt().options.websocket
1818
})
1919
})
2020

2121
test('should render the template', () => {
2222
expectModuleToBeCalledWith('addTemplate', {
23-
src: 'src/templates/WebSocketManager.ts',
23+
src: require.resolve('../src/templates/WebSocketManager.ts'),
2424
fileName: 'nuxt-websocket/WebSocketManager.ts',
2525
options: getNuxt().options.websocket
2626
})

0 commit comments

Comments
 (0)