From c6f5dbe664bdafbea549d143fb3733527d300cf4 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Thu, 14 Nov 2024 23:47:52 +0100 Subject: [PATCH 1/3] fix: use resolveId to mark #applicationinsights as sideeffect and external --- src/module.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/module.ts b/src/module.ts index 98e53aab..86b3470c 100644 --- a/src/module.ts +++ b/src/module.ts @@ -9,12 +9,6 @@ export default { if (!nitro.options.externals) { nitro.options.externals = {} } - - nitro.options.alias['#applicationinsights'] = await resolvePath('nitro-applicationinsights/runtime/applicationinsights', { - extensions: ['.ts', '.mjs', '.js'], - url: [import.meta.url] - }) - nitro.options.externals.inline = nitro.options.externals.inline || [] // force inline the plugin and the setup file nitro.options.externals.inline.push((id) => ( @@ -40,6 +34,12 @@ export default { } } }, + externals: { + traceInclude: [ + // the main file doesn't seems to be traced + await resolvePath('applicationinsights/out/applicationinsights.js') + ] + }, rollupConfig: { plugins: [ // add necessary global var for applicationinsights @@ -63,6 +63,18 @@ export default { }; } } + }, + { + name: 'applicationinsights-loader', + resolveId(id) { + if (id === '#applicationinsights') { + return { + id: 'applicationinsights', + moduleSideEffects: true, + external: true + } + } + }, } ] } From a6ccf928878127d5afcfdbb0d91866106ea562f4 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Thu, 14 Nov 2024 23:58:05 +0100 Subject: [PATCH 2/3] fix: move again to applicationinsights --- src/module.ts | 2 +- src/runtime/plugin.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/module.ts b/src/module.ts index 86b3470c..50309fea 100644 --- a/src/module.ts +++ b/src/module.ts @@ -67,7 +67,7 @@ export default { { name: 'applicationinsights-loader', resolveId(id) { - if (id === '#applicationinsights') { + if (id === '#applicationinsights' || id === 'applicationinsights') { return { id: 'applicationinsights', moduleSideEffects: true, diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index fcbbb441..2f816ed8 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -4,8 +4,8 @@ import type { NitroApp, NitroAppPlugin } from 'nitropack' import defu from 'defu' import type { TNitroAppInsightsConfig } from '../types' import { useRuntimeConfig } from '#imports' -import _Applicationinsights from '#applicationinsights' -import type { Contracts } from '#applicationinsights' +import _Applicationinsights from 'applicationinsights' +import type { Contracts } from 'applicationinsights' const Applicationinsights = _Applicationinsights as typeof import('applicationinsights') export default (async (nitro) => { From 981e99a9d1412a75d7e740f9cd1694b8cc4c7372 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Fri, 15 Nov 2024 00:04:37 +0100 Subject: [PATCH 3/3] refactor: remove `#applicationinsights` --- .../1.guide/4.importing-applicationinsights.md | 7 ------- src/module.ts | 14 +------------- src/runtime/applicationinsights.ts | 3 --- 3 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 docs/content/1.guide/4.importing-applicationinsights.md delete mode 100644 src/runtime/applicationinsights.ts diff --git a/docs/content/1.guide/4.importing-applicationinsights.md b/docs/content/1.guide/4.importing-applicationinsights.md deleted file mode 100644 index 7123f3ad..00000000 --- a/docs/content/1.guide/4.importing-applicationinsights.md +++ /dev/null @@ -1,7 +0,0 @@ -# Importing Application Insights in your project - -Because Applicationinsights is written in CommonJS, there's currently some bug in dev or build mode. - -When you need to import `applicationinsights` in your project, prefer using `#applicationinsights` instead. - -Also avoid using `import * as` when importing `applicationinsights` or `#applicationinsights`, this will import everything from `applicationinsights` and Rollup will try to inline all files from `applicationinsights`. This will result into a faulty build. \ No newline at end of file diff --git a/src/module.ts b/src/module.ts index 50309fea..6ebabf17 100644 --- a/src/module.ts +++ b/src/module.ts @@ -22,18 +22,6 @@ export default { })) nitro.options = defu(nitro.options, { - typescript: { - tsConfig: { - compilerOptions: { - paths: { - '#applicationinsights': [await resolvePath('nitro-applicationinsights/runtime/applicationinsights', { - extensions: ['.ts', '.mjs', '.js'], - url: [import.meta.url] - })] - } - } - } - }, externals: { traceInclude: [ // the main file doesn't seems to be traced @@ -67,7 +55,7 @@ export default { { name: 'applicationinsights-loader', resolveId(id) { - if (id === '#applicationinsights' || id === 'applicationinsights') { + if (id === 'applicationinsights') { return { id: 'applicationinsights', moduleSideEffects: true, diff --git a/src/runtime/applicationinsights.ts b/src/runtime/applicationinsights.ts deleted file mode 100644 index 54612d3a..00000000 --- a/src/runtime/applicationinsights.ts +++ /dev/null @@ -1,3 +0,0 @@ -// this file re-export the applicationinsights module. plugin.ts is inlined so we need to avoid having applicationinsights being inlined as well -export { default } from 'applicationinsights'; -export * from "applicationinsights"