@vue-storefront/nuxt 2.8.0 → 3.0.0-rc.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Vue Storefront
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @vue-storefront/nuxt
2
+
3
+ ## Quick Setup
4
+
5
+ 1. Add `@vue-storefront/nuxt` dependency to your project
6
+
7
+ ```bash
8
+ # Using pnpm
9
+ pnpm add -D @vue-storefront/nuxt
10
+
11
+ # Using yarn
12
+ yarn add --dev @vue-storefront/nuxt
13
+
14
+ # Using npm
15
+ npm install --save-dev @vue-storefront/nuxt
16
+ ```
17
+
18
+ 2. Add `@vue-storefront/nuxt` to the `modules` section of `nuxt.config.ts`
19
+
20
+ ```js
21
+ export default defineNuxtConfig({
22
+ modules: ["@vue-storefront/nuxt"],
23
+ });
24
+ ```
25
+
26
+ 3. Configure the module
27
+
28
+ There are two ways you can configure the SDK module. The first is by using the `vsf` key in the Nuxt configuration object and providing necessary information such as the Middleware instance address:
29
+
30
+ ```ts
31
+ export default defineNuxtConfig({
32
+ modules: ["@vue-storefront/nuxt"],
33
+ vsf: {
34
+ middleware: {
35
+ apiUrl: "http://localhost:3000"
36
+ }
37
+ },
38
+ });
39
+ ```
40
+
41
+ 4. Create SDK config file - `sdk.config.ts` in root directory of your project:
42
+
43
+ The `defineSdkConfig` function is used for this purpose. The parameter for calling this function should be an anonymous function that receives an injected context from the module, containing:
44
+
45
+ - the `buildModule` function,
46
+ - the middleware URL (`middlewareUrl`),
47
+ - a function for retrieving the Cookie header with cookie values (`getCookieHeader`).
48
+
49
+ You should import all other SDK configuration components. See the example below illustrating the SDK configuration with Unified and Contentful modules.
50
+
51
+ ```ts
52
+ import {
53
+ contentfulModule,
54
+ ContentfulModuleType,
55
+ } from "@vsf-enterprise/contentful-sdk";
56
+ import { unifiedModule } from "@vsf-enterprise/unified-sdk";
57
+ import type { UnifiedApiExtension } from "../storefront-middleware/middleware.config";
58
+
59
+ export default defineSdkConfig(
60
+ ({ buildModule, middlewareUrl, getCookieHeader }) => ({
61
+ unified: buildModule(unifiedModule<UnifiedApiExtension>, {
62
+ apiUrl: middlewareUrl + "/commerce",
63
+ requestOptions: {
64
+ headers: getCookieHeader,
65
+ },
66
+ }),
67
+ contentful: buildModule<ContentfulModuleType>(contentfulModule, {
68
+ apiUrl: middlewareUrl + "/cntf",
69
+ }),
70
+ }),
71
+ );
72
+ ```
73
+
74
+ That's it! You can now use VueStorefront Module in your Nuxt app ✨
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -0,0 +1,30 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface MiddlewareConfig {
4
+ /**
5
+ * The URL of the middleware.
6
+ * @example "http://localhost:4000"
7
+ */
8
+ apiUrl: string;
9
+ /**
10
+ * The URL of the middleware for server-side rendering.
11
+ * @example "http://localhost:4000"
12
+ */
13
+ ssrApiUrl?: string;
14
+ }
15
+ interface MultistoreConfig {
16
+ /**
17
+ * Whether the multistore is enabled or not.
18
+ * @example false
19
+ * @default false
20
+ */
21
+ enabled: boolean;
22
+ }
23
+ interface SdkModuleOptions {
24
+ middleware: MiddlewareConfig;
25
+ multistore?: MultistoreConfig;
26
+ }
27
+
28
+ declare const _default: _nuxt_schema.NuxtModule<SdkModuleOptions>;
29
+
30
+ export { _default as default };
@@ -0,0 +1,30 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface MiddlewareConfig {
4
+ /**
5
+ * The URL of the middleware.
6
+ * @example "http://localhost:4000"
7
+ */
8
+ apiUrl: string;
9
+ /**
10
+ * The URL of the middleware for server-side rendering.
11
+ * @example "http://localhost:4000"
12
+ */
13
+ ssrApiUrl?: string;
14
+ }
15
+ interface MultistoreConfig {
16
+ /**
17
+ * Whether the multistore is enabled or not.
18
+ * @example false
19
+ * @default false
20
+ */
21
+ enabled: boolean;
22
+ }
23
+ interface SdkModuleOptions {
24
+ middleware: MiddlewareConfig;
25
+ multistore?: MultistoreConfig;
26
+ }
27
+
28
+ declare const _default: _nuxt_schema.NuxtModule<SdkModuleOptions>;
29
+
30
+ export { _default as default };
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@vue-storefront/nuxt",
3
+ "configKey": "vsf",
4
+ "compatibility": {
5
+ "nuxt": "^3.0.0"
6
+ },
7
+ "version": "3.0.0-rc.0"
8
+ }
@@ -0,0 +1,80 @@
1
+ import { defineNuxtModule, createResolver, addTypeTemplate, addImports, addTemplate, addPluginTemplate, addImportsSources } from '@nuxt/kit';
2
+ import { genInlineTypeImport } from 'knitwork';
3
+
4
+ const module = defineNuxtModule({
5
+ meta: {
6
+ name: "@vue-storefront/nuxt",
7
+ configKey: "vsf",
8
+ compatibility: {
9
+ nuxt: "^3.0.0"
10
+ }
11
+ },
12
+ defaults: {
13
+ middleware: {
14
+ apiUrl: "http://localhost:4000"
15
+ },
16
+ multistore: {
17
+ enabled: false
18
+ }
19
+ },
20
+ setup(options, nuxt) {
21
+ const projectLayer = nuxt.options._layers[0];
22
+ const projectRootResolver = createResolver(projectLayer.config.rootDir);
23
+ const buildDirResolver = createResolver(nuxt.options.buildDir);
24
+ const localResolver = createResolver(import.meta.url);
25
+ nuxt.options.app.head.meta = [
26
+ ...nuxt.options.app.head.meta ?? [],
27
+ {
28
+ name: "generator",
29
+ content: "Vue Storefront 2"
30
+ }
31
+ ];
32
+ addTypeTemplate({
33
+ filename: "sdk.config.d.ts",
34
+ getContents: () => `
35
+ export type SdkConfig = ${genInlineTypeImport(
36
+ projectRootResolver.resolve("sdk.config")
37
+ )}
38
+ `
39
+ });
40
+ addTypeTemplate({
41
+ filename: "vsfModule.d.ts",
42
+ src: localResolver.resolve("./runtime/types.template")
43
+ });
44
+ addImports({
45
+ name: "composeMiddlewareUrl",
46
+ as: "composeMiddlewareUrl",
47
+ from: localResolver.resolve("./runtime/utils/composeMiddlewareUrl")
48
+ });
49
+ addTemplate({
50
+ src: localResolver.resolve("./runtime/useSdk.template"),
51
+ filename: "useSdk.ts",
52
+ write: true
53
+ });
54
+ addTemplate({
55
+ src: localResolver.resolve("./runtime/defineSdkConfig.template"),
56
+ filename: "defineSdkConfig.ts",
57
+ write: true,
58
+ options: {
59
+ moduleConfig: JSON.stringify(options)
60
+ }
61
+ });
62
+ addPluginTemplate({
63
+ src: localResolver.resolve("./runtime/plugin.template"),
64
+ filename: "vsfSdkPlugin.ts",
65
+ write: true
66
+ });
67
+ addImportsSources([
68
+ {
69
+ imports: ["useSdk"],
70
+ from: buildDirResolver.resolve("useSdk.ts")
71
+ },
72
+ {
73
+ imports: ["defineSdkConfig"],
74
+ from: buildDirResolver.resolve("defineSdkConfig.ts")
75
+ }
76
+ ]);
77
+ }
78
+ });
79
+
80
+ export { module as default };
@@ -0,0 +1,68 @@
1
+ import { buildModule } from "@vue-storefront/sdk";
2
+ import { composeMiddlewareUrl, useNuxtApp, useRequestHeaders } from "#imports";
3
+ import { SdkModuleOptions } from "./vsfModule";
4
+
5
+ type InjectedContext = {
6
+ buildModule: typeof buildModule;
7
+ middlewareUrl: string;
8
+ getCookieHeader: () => Record<string, string>;
9
+ };
10
+
11
+ type Config<TConfig> = (context: InjectedContext) => TConfig;
12
+
13
+ const moduleConfig: SdkModuleOptions = <%= options.moduleConfig %>;
14
+
15
+ /**
16
+ * Define SDK config function
17
+ *
18
+ * @param config - Function that returns SDK config
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import {
23
+ * contentfulModule,
24
+ * ContentfulModuleType,
25
+ * } from "@vsf-enterprise/contentful-sdk";
26
+ * import { unifiedModule } from "@vsf-enterprise/unified-sdk";
27
+ * import type { UnifiedApiExtension } from "../storefront-middleware/middleware.config";
28
+ *
29
+ * export default defineSdkConfig(
30
+ * ({ buildModule, middlewareUrl, getCookieHeader }) => ({
31
+ * unified: buildModule(unifiedModule<UnifiedApiExtension>, {
32
+ * apiUrl: middlewareUrl + "/commerce",
33
+ * requestOptions: {
34
+ * headers: getCookieHeader,
35
+ * },
36
+ * }),
37
+ * contentful: buildModule<ContentfulModuleType>(contentfulModule, {
38
+ * apiUrl: middlewareUrl + "/cntf",
39
+ * }),
40
+ * }),
41
+ * );
42
+ * ```
43
+ */
44
+ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
45
+ return () => {
46
+ const nuxtApp = useNuxtApp()
47
+ const runtimeConfig = useRuntimeConfig();
48
+ const { middleware, multistore } = runtimeConfig.public;
49
+ const resolvedOptions = {
50
+ middleware: middleware ?? moduleConfig.middleware,
51
+ multistore: multistore ?? moduleConfig.multistore,
52
+ }
53
+
54
+ const requestHeaders = useRequestHeaders(["x-forwarded-host", "host"]);
55
+ const middlewareUrl = composeMiddlewareUrl({
56
+ options: resolvedOptions,
57
+ headers: requestHeaders,
58
+ });
59
+
60
+ const getCookieHeader = () => useRequestHeaders(["cookie"]);
61
+
62
+ return config({
63
+ buildModule,
64
+ middlewareUrl,
65
+ getCookieHeader
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,10 @@
1
+ import { initSDK } from "@vue-storefront/sdk"
2
+ import sdkConfig from "~/sdk.config"
3
+ import { defineNuxtPlugin } from '#app'
4
+
5
+ export default defineNuxtPlugin((nuxtApp) => {
6
+ const config = sdkConfig();
7
+ const sdk = initSDK<typeof config>(config);
8
+
9
+ nuxtApp.provide("vsf", { sdk });
10
+ })
@@ -0,0 +1,13 @@
1
+ export interface MiddlewareConfig {
2
+ apiUrl: string;
3
+ ssrApiUrl?: string;
4
+ }
5
+
6
+ export interface MultistoreConfig {
7
+ enabled: boolean;
8
+ }
9
+
10
+ export interface SdkModuleOptions {
11
+ middleware: MiddlewareConfig;
12
+ multistore?: MultistoreConfig;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { SdkConfig } from "./sdk.config";
2
+ import type { SDKApi } from '@vue-storefront/sdk';
3
+ import { useNuxtApp } from "#imports";
4
+
5
+ export const useSdk = () => {
6
+ const nuxtApp = useNuxtApp();
7
+ const { sdk } = nuxtApp.$vsf;
8
+
9
+ return sdk as SDKApi<ReturnType<SdkConfig>>;
10
+ };
@@ -0,0 +1,11 @@
1
+ import { SdkModuleOptions } from "~/src/types";
2
+ interface ComposeMiddlewareUrlParams {
3
+ options: SdkModuleOptions;
4
+ headers: Record<string, string | string[]>;
5
+ }
6
+ /**
7
+ *
8
+ * @description A helper function to compute the middleware url. It will be used only internally in the package
9
+ */
10
+ export declare function composeMiddlewareUrl({ options, headers, }: ComposeMiddlewareUrlParams): string;
11
+ export {};
@@ -0,0 +1,29 @@
1
+ function calculateMiddlewareUrl({
2
+ options,
3
+ headers
4
+ }) {
5
+ const { apiUrl, ssrApiUrl } = options.middleware;
6
+ if (typeof window !== "undefined") {
7
+ return apiUrl;
8
+ }
9
+ if (ssrApiUrl) {
10
+ return ssrApiUrl;
11
+ }
12
+ if (!options.multistore?.enabled) {
13
+ return apiUrl;
14
+ }
15
+ const forwardedHost = headers["x-forwarded-host"] ?? headers.host;
16
+ const url = new URL(apiUrl);
17
+ url.host = forwardedHost && [...forwardedHost].join("") || new URL(apiUrl).host;
18
+ return url.href;
19
+ }
20
+ function removeTrailingSlash(url) {
21
+ return url.replace(/\/$/, "");
22
+ }
23
+ export function composeMiddlewareUrl({
24
+ options,
25
+ headers
26
+ }) {
27
+ const url = calculateMiddlewareUrl({ options, headers });
28
+ return removeTrailingSlash(url);
29
+ }
@@ -0,0 +1,7 @@
1
+
2
+ import { } from './module'
3
+
4
+
5
+
6
+
7
+ export { default } from './module'
@@ -0,0 +1,7 @@
1
+
2
+ import { } from './module'
3
+
4
+
5
+
6
+
7
+ export { default } from './module'
package/package.json CHANGED
@@ -1,38 +1,48 @@
1
1
  {
2
2
  "name": "@vue-storefront/nuxt",
3
- "version": "2.8.0",
4
- "main": "lib/index.cjs.js",
5
- "module": "lib/index.es.js",
6
- "types": "lib/src/index.d.ts",
3
+ "version": "3.0.0-rc.0",
4
+ "description": "Vue Storefront dedicated features for Nuxt",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/module.mjs",
11
+ "require": "./dist/module.cjs"
12
+ }
13
+ },
14
+ "main": "./dist/module.cjs",
15
+ "types": "./dist/types.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
7
19
  "scripts": {
8
- "build": "rimraf lib && rollup -c",
9
- "test": "echo \"Error: no test specified\"",
10
- "prepublish": "yarn build"
20
+ "build": "nuxt-module-build build && yarn build:app",
21
+ "build:app": "cd __tests__/app && yarn build",
22
+ "dev": "cd __tests__/app && yarn dev",
23
+ "dev:middleware": "cd ../../shared/src/__tests__/middleware && yarn dev",
24
+ "lint": "eslint --ext .vue,.js,.ts .",
25
+ "test": "start-server-and-test dev:middleware localhost:4000/test_integration/success dev localhost:3000/ssr \"yarn test:e2e\"",
26
+ "test:e2e": "cd ../../shared/ && yarn test:e2e",
27
+ "test:watch": "vitest watch",
28
+ "postinstall": "nuxi prepare"
29
+ },
30
+ "peerDependencies": {
31
+ "@vue-storefront/sdk": "^1.0.0"
11
32
  },
12
- "author": "Vue Storefront",
13
- "license": "MIT",
14
33
  "dependencies": {
15
- "@nuxt/typescript-build": "^2.0.0",
16
- "@nuxtjs/composition-api": "^0.29.3",
17
- "@nuxtjs/style-resources": "^1.0.0",
18
- "chalk": "^2.4.2",
19
- "chokidar": "^3.3.1",
20
- "consola": "^2.10.1",
21
- "lodash": "^4.17.15",
22
- "nuxt-purgecss": "^1.0.0"
34
+ "@nuxt/kit": "3.7.4",
35
+ "knitwork": "^1.0.0"
23
36
  },
24
37
  "devDependencies": {
25
- "@nuxt/types": "^2.15.8",
26
- "@rollup/plugin-json": "~4.1.0"
27
- },
28
- "publishConfig": {
29
- "access": "public"
30
- },
31
- "files": [
32
- "lib/**/*",
33
- "plugins/**/*"
34
- ],
35
- "engines": {
36
- "node": ">= 14"
38
+ "@types/node": "^18.11.17",
39
+ "@nuxt/devtools": "^1.0.0",
40
+ "@nuxt/module-builder": "0.5.2",
41
+ "@nuxt/schema": "3.7.4",
42
+ "@nuxt/test-utils": "3.7.4",
43
+ "@vue-storefront/sdk": "*",
44
+ "nuxt": "3.7.4",
45
+ "start-server-and-test": "^2.0.3",
46
+ "vitest": "^0.34.6"
37
47
  }
38
48
  }
package/lib/index.cjs.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),n=require("path"),t=require("consola"),r=require("chalk"),s=require("lodash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=o(e),i=o(n),c=o(t),l=o(r),a=Object.freeze({info:function(e){return c.default.info(l.default.bold("VSF"),e)},success:function(e){return c.default.success(l.default.bold("VSF"),e)},warning:function(e){return c.default.warn(l.default.bold("VSF"),e)},error:function(e){return c.default.error(l.default.bold("VSF"),e)}}),d=function(e,n){return s.mergeWith(e,n,(function(e,n){if(s.isArray(e))return e.concat(n)}))};function p(e){try{return require.resolve(e,{paths:[process.cwd()]})}catch(e){return""}}function f(){this.options.render=s.merge(this.options.render,{http2:{push:!0,pushAssets:function(e,n,t,r){return r.filter((function(e){return"script"===e.asType})).map((function(e){var n=e.file,r=e.asType;return"<".concat(t).concat(n,">; rel=preload; as=").concat(r)}))}}})}function h(e){this.nuxt.hook("modules:done",(function(n){return n.addModule(["nuxt-purgecss",e])}))}function g(e){var n=e.performance,t=n.httpPush,r=n.purgeCSS;t&&f.call(this),r&&r.enabled&&h.call(this,r)}function v(e){var n=["@storefront-ui/vue","@storefront-ui/shared"];e.useRawSource=d(e.useRawSource,{dev:n,prod:n})}function m(e){v.call(this,e)}function S(e){var n=this;e.useRawSource[function(e){return"production"===process.env.NODE_ENV||e.coreDevelopment}(e)?"prod":"dev"].map((function(e){return function(e){var t=p("".concat(e,"/package.json")),r=require(t||"");r.module&&n.extendBuild((function(n){n.resolve.alias[r.name+"$"]=p("".concat(e,"/").concat(r.module))})),n.options.build.transpile.push(e),a.info("Using raw source/ESM for ".concat(r.name))}(e)}))}var x={name:"@vue-storefront/nuxt",version:"2.8.0",main:"lib/index.cjs.js",module:"lib/index.es.js",types:"lib/src/index.d.ts",scripts:{build:"rimraf lib && rollup -c",test:'echo "Error: no test specified"',prepublish:"yarn build"},author:"Vue Storefront",license:"MIT",dependencies:{"@nuxt/typescript-build":"^2.0.0","@nuxtjs/composition-api":"^0.29.3","@nuxtjs/style-resources":"^1.0.0",chalk:"^2.4.2",chokidar:"^3.3.1",consola:"^2.10.1",lodash:"^4.17.15","nuxt-purgecss":"^1.0.0"},devDependencies:{"@nuxt/types":"^2.15.8","@rollup/plugin-json":"~4.1.0"},publishConfig:{access:"public"},files:["lib/**/*","plugins/**/*"],engines:{node:">= 14"}};exports.default=function(e){var n=d({coreDevelopment:!1,i18nExtension:!0,e2e:!0,logger:!0,ssr:!0,context:!0,sfui:!0,performance:{httpPush:!0,purgeCSS:{enabled:!1,paths:["**/*.vue"]}},useRawSource:{dev:[],prod:[]}},e);this.options.head.meta.push({name:"generator",content:"Vue Storefront 2"}),a.info("Starting Vue Storefront Nuxt Module"),n.performance.httpPush&&(this.options.render=d(this.options.render,{http2:{push:!0,pushAssets:function(e,n,t,r){return r.filter((function(e){return"script"===e.asType})).map((function(e){var n=e.file,r=e.asType;return"<".concat(t).concat(n,">; rel=preload; as=").concat(r)}))}}})),n.context&&(this.addPlugin(i.default.resolve(__dirname,"../plugins/context.js")),a.success("Installed Vue Storefront Context plugin")),n.ssr&&(this.addPlugin(i.default.resolve(__dirname,"../plugins/ssr.js")),a.success("Installed Vue Storefront SSR plugin")),n.logger&&(this.addPlugin({src:i.default.resolve(__dirname,"../plugins/logger.js"),options:e.logger||{}}),a.success("Installed VSF Logger plugin")),n.e2e&&(this.addPlugin(i.default.resolve(__dirname,"../plugins/e2e-testing.js")),a.success("Installed Vue Storefront E2E testing plugin")),n.i18nExtension&&(this.addPlugin({src:i.default.resolve(__dirname,"../plugins/i18n-cookies.js"),options:this.options.i18n}),a.success("Installed Internationalization Cookies plugin")),u.default.existsSync(p("@storefront-ui/vue"))&&n.sfui&&(m.call(this,n),a.success("Installed StorefrontUI Module")),g.call(this,n),a.success("Installed Performance Module"),S.call(this,n)},exports.meta=x;
2
- //# sourceMappingURL=index.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/helpers/log.ts","../src/helpers/merge.ts","../src/helpers/resolveDependency.ts","../src/modules/performance.ts","../src/modules/storefront-ui.ts","../src/modules/raw-sources-loader.ts","../src/helpers/isProduction.ts","../src/index.ts"],"sourcesContent":["import consola from 'consola';\nimport chalk from 'chalk';\nimport { Log } from '../types';\n\nconst log: Log = Object.freeze({\n info: (message) => consola.info(chalk.bold('VSF'), message),\n success: (message) => consola.success(chalk.bold('VSF'), message),\n warning: (message) => consola.warn(chalk.bold('VSF'), message),\n error: (message) => consola.error(chalk.bold('VSF'), message)\n});\n\nexport default log;\n","import { mergeWith, isArray } from 'lodash';\n\nexport default (source, destination) => mergeWith(source, destination, (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n});\n","export default function resolveDependency(name: string): string {\n try {\n return require.resolve(name, { paths: [process.cwd()] });\n } catch (error) {\n return '';\n }\n}\n","import { merge } from 'lodash';\nimport { ModuleOptions, PurgeCSSOptions } from '../types';\n\nfunction pushScripts(): void {\n this.options.render = merge(this.options.render, {\n http2: {\n push: true,\n pushAssets: (request, response, publicPath, preloadFiles) => {\n return preloadFiles\n .filter(({ asType }) => asType === 'script')\n .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`);\n }\n }\n });\n}\n\nfunction loadPurgeCss(options: PurgeCSSOptions): void {\n // PurgeCSS module should be installed after all other modules\n this.nuxt.hook('modules:done', moduleContainer => moduleContainer.addModule(['nuxt-purgecss', options]));\n}\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n const { httpPush, purgeCSS } = options.performance;\n\n if (httpPush) {\n pushScripts.call(this);\n }\n\n if (purgeCSS && purgeCSS.enabled) {\n loadPurgeCss.call(this, purgeCSS);\n }\n}\n","import merge from '../helpers/merge';\nimport { ModuleOptions } from '../types';\n\n// TODO: Create a separate nuxt module for storefront ui\nfunction loadStorefrontRawSources(options: ModuleOptions): void {\n const rawSources = [\n '@storefront-ui/vue',\n '@storefront-ui/shared'\n ];\n\n options.useRawSource = merge(options.useRawSource, {\n dev: rawSources,\n prod: rawSources\n });\n}\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n loadStorefrontRawSources.call(this, options);\n}\n","import log from '../helpers/log';\nimport isProduction from '../helpers/isProduction';\nimport resolveDependency from '../helpers/resolveDependency';\nimport { ModuleOptions } from '../types';\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n const useRawSource = (pckg) => {\n const pkgPath = resolveDependency(`${pckg}/package.json`);\n // eslint-disable-next-line global-require\n const pkg = require(pkgPath || '');\n\n if (pkg.module) {\n this.extendBuild(config => {\n config.resolve.alias[pkg.name + '$'] = resolveDependency(`${pckg}/${pkg.module}`);\n });\n }\n\n this.options.build.transpile.push(pckg);\n log.info(`Using raw source/ESM for ${pkg.name}`);\n };\n\n options.useRawSource[isProduction(options) ? 'prod' : 'dev'].map(pckg => useRawSource(pckg));\n}\n","import { ModuleOptions } from '../types';\n\nexport default (options: ModuleOptions): boolean => process.env.NODE_ENV === 'production' || options.coreDevelopment;\n","// TODO proper bundling, for now it's just to experiment with nuxt modules api\nimport fs from 'fs';\nimport path from 'path';\nimport log from './helpers/log';\nimport merge from './helpers/merge';\nimport resolveDependency from './helpers/resolveDependency';\nimport performanceModule from './modules/performance';\nimport storefrontUiModule from './modules/storefront-ui';\nimport rawSourcesModule from './modules/raw-sources-loader';\nimport { ModuleOptions } from './types';\n\nexport { default as meta } from '../package.json';\n\n/**\n * VueStorefrontNuxtModule\n * @param moduleOptions\n */\nexport default function VueStorefrontNuxtModule(moduleOptions: ModuleOptions) {\n const defaultOptions = {\n coreDevelopment: false,\n i18nExtension: true,\n e2e: true,\n logger: true,\n ssr: true,\n context: true,\n sfui: true,\n performance: {\n httpPush: true,\n purgeCSS: {\n enabled: false,\n paths: ['**/*.vue']\n }\n },\n useRawSource: {\n dev: [],\n prod: []\n }\n };\n\n const options = merge(defaultOptions, moduleOptions);\n\n // Add meta data\n this.options.head.meta.push({\n name: 'generator',\n content: 'Vue Storefront 2'\n });\n\n log.info('Starting Vue Storefront Nuxt Module');\n\n // Enable HTTP/2 push for JS files\n if (options.performance.httpPush) {\n this.options.render = merge(this.options.render, {\n http2: {\n push: true,\n pushAssets: (request, response, publicPath, preloadFiles) => {\n return preloadFiles\n .filter(({ asType }) => asType === 'script')\n .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`);\n }\n }\n });\n }\n\n if (options.context) {\n // Context plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/context.js'));\n log.success('Installed Vue Storefront Context plugin');\n }\n if (options.ssr) {\n // SSR plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/ssr.js'));\n log.success('Installed Vue Storefront SSR plugin');\n }\n\n if (options.logger) {\n // Logger plugin\n this.addPlugin({\n src: path.resolve(__dirname, '../plugins/logger.js'),\n options: moduleOptions.logger || {}\n });\n log.success('Installed VSF Logger plugin');\n }\n\n if (options.e2e) {\n // Context plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/e2e-testing.js'));\n log.success('Installed Vue Storefront E2E testing plugin');\n }\n\n // i18n-cookies plugin\n if (options.i18nExtension) {\n this.addPlugin({\n src: path.resolve(__dirname, '../plugins/i18n-cookies.js'),\n options: this.options.i18n\n });\n log.success('Installed Internationalization Cookies plugin');\n }\n\n // StorefrontUI module\n if (fs.existsSync(resolveDependency('@storefront-ui/vue')) && options.sfui) {\n storefrontUiModule.call(this, options);\n log.success('Installed StorefrontUI Module');\n }\n\n // Performance module\n performanceModule.call(this, options);\n log.success('Installed Performance Module');\n\n // Raw sources loader\n rawSourcesModule.call(this, options);\n}\n"],"names":["log","Object","freeze","info","message","consola","chalk","bold","success","warning","warn","error","merge","source","destination","mergeWith","objValue","srcValue","isArray","concat","resolveDependency","name","require","resolve","paths","process","cwd","pushScripts","this","options","render","http2","push","pushAssets","request","response","publicPath","preloadFiles","filter","_a","asType","map","file","loadPurgeCss","nuxt","hook","moduleContainer","addModule","VueStorefrontPerformanceModule","performance","httpPush","purgeCSS","call","enabled","loadStorefrontRawSources","rawSources","useRawSource","dev","prod","_this","env","NODE_ENV","coreDevelopment","isProduction","pckg","pkgPath","pkg","module","extendBuild","config","alias","build","transpile","moduleOptions","i18nExtension","e2e","logger","ssr","context","sfui","head","meta","content","addPlugin","path","__dirname","src","i18n","fs","existsSync","stor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AUC,EAAYC,GAC1C,OAAOA,EACJC,QAAO,SAACC,GAAe,MAAW,WAAlBA,EAAAC,UAChBC,KAAI,SAACF,OAAEG,EAAIH,EAAAG,KAAEF,EAAMD,EAAAC,OAAO,MAAA,WAAIJ,GAAUjB,OAAGuB,EAAI,uBAAAvB,OAAsBqB,WAM5EX,EAAQiD,UAEVlD,KAAKuD,UAAUC,EAAI,QAAC7D,QAAQ8D,UAAW,0BACvCrF,EAAIQ,QAAQ,4CAEVqB,EAAQgD,MAEVjD,KAAKuD,UAAUC,EAAI,QAAC7D,QAAQ8D,UAAW,sBACvCrF,EAAIQ,QAAQ,wCAGVqB,EAAQ+C,SAEVhD,KAAKuD,UAAU,CACbG,IAAKF,EAAI,QAAC7D,QAAQ8D,UAAW,wBAC7BxD,QAAS4C,EAAcG,QAAU,KAEnC5E,EAAIQ,QAAQ,gCAGVqB,EAAQ8C,MAEV/C,KAAKuD,UAAUC,EAAI,QAAC7D,QAAQ8D,UAAW,8BACvCrF,EAAIQ,QAAQ,gDAIVqB,EAAQ6C,gBACV9C,KAAKuD,UAAU,CACbG,IAAKF,EAAI,QAAC7D,QAAQ8D,UAAW,8BAC7BxD,QAASD,KAAKC,QAAQ0D,OAExBvF,EAAIQ,QAAQ,kDAIVgF,EAAAA,QAAGC,WAAWrE,EAAkB,wBAA0BS,EAAQkD,OACpEW,EAAmBtC,KAAKxB,KAAMC,GAC9B7B,EAAIQ,QAAQ,kCAIdmF,EAAkBvC,KAAKxB,KAAMC,GAC7B7B,EAAIQ,QAAQ,gCAGZoF,EAAiBxC,KAAKxB,KAAMC"}
package/lib/index.es.js DELETED
@@ -1,2 +0,0 @@
1
- import e from"fs";import n from"path";import t from"consola";import s from"chalk";import{mergeWith as o,isArray as r,merge as i}from"lodash";var u=Object.freeze({info:function(e){return t.info(s.bold("VSF"),e)},success:function(e){return t.success(s.bold("VSF"),e)},warning:function(e){return t.warn(s.bold("VSF"),e)},error:function(e){return t.error(s.bold("VSF"),e)}}),c=function(e,n){return o(e,n,(function(e,n){if(r(e))return e.concat(n)}))};function l(e){try{return require.resolve(e,{paths:[process.cwd()]})}catch(e){return""}}function a(){this.options.render=i(this.options.render,{http2:{push:!0,pushAssets:function(e,n,t,s){return s.filter((function(e){return"script"===e.asType})).map((function(e){var n=e.file,s=e.asType;return"<".concat(t).concat(n,">; rel=preload; as=").concat(s)}))}}})}function p(e){this.nuxt.hook("modules:done",(function(n){return n.addModule(["nuxt-purgecss",e])}))}function d(e){var n=e.performance,t=n.httpPush,s=n.purgeCSS;t&&a.call(this),s&&s.enabled&&p.call(this,s)}function f(e){var n=["@storefront-ui/vue","@storefront-ui/shared"];e.useRawSource=c(e.useRawSource,{dev:n,prod:n})}function h(e){f.call(this,e)}function g(e){var n=this;e.useRawSource[function(e){return"production"===process.env.NODE_ENV||e.coreDevelopment}(e)?"prod":"dev"].map((function(e){return function(e){var t=l("".concat(e,"/package.json")),s=require(t||"");s.module&&n.extendBuild((function(n){n.resolve.alias[s.name+"$"]=l("".concat(e,"/").concat(s.module))})),n.options.build.transpile.push(e),u.info("Using raw source/ESM for ".concat(s.name))}(e)}))}var m={name:"@vue-storefront/nuxt",version:"2.8.0",main:"lib/index.cjs.js",module:"lib/index.es.js",types:"lib/src/index.d.ts",scripts:{build:"rimraf lib && rollup -c",test:'echo "Error: no test specified"',prepublish:"yarn build"},author:"Vue Storefront",license:"MIT",dependencies:{"@nuxt/typescript-build":"^2.0.0","@nuxtjs/composition-api":"^0.29.3","@nuxtjs/style-resources":"^1.0.0",chalk:"^2.4.2",chokidar:"^3.3.1",consola:"^2.10.1",lodash:"^4.17.15","nuxt-purgecss":"^1.0.0"},devDependencies:{"@nuxt/types":"^2.15.8","@rollup/plugin-json":"~4.1.0"},publishConfig:{access:"public"},files:["lib/**/*","plugins/**/*"],engines:{node:">= 14"}};function v(t){var s=c({coreDevelopment:!1,i18nExtension:!0,e2e:!0,logger:!0,ssr:!0,context:!0,sfui:!0,performance:{httpPush:!0,purgeCSS:{enabled:!1,paths:["**/*.vue"]}},useRawSource:{dev:[],prod:[]}},t);this.options.head.meta.push({name:"generator",content:"Vue Storefront 2"}),u.info("Starting Vue Storefront Nuxt Module"),s.performance.httpPush&&(this.options.render=c(this.options.render,{http2:{push:!0,pushAssets:function(e,n,t,s){return s.filter((function(e){return"script"===e.asType})).map((function(e){var n=e.file,s=e.asType;return"<".concat(t).concat(n,">; rel=preload; as=").concat(s)}))}}})),s.context&&(this.addPlugin(n.resolve(__dirname,"../plugins/context.js")),u.success("Installed Vue Storefront Context plugin")),s.ssr&&(this.addPlugin(n.resolve(__dirname,"../plugins/ssr.js")),u.success("Installed Vue Storefront SSR plugin")),s.logger&&(this.addPlugin({src:n.resolve(__dirname,"../plugins/logger.js"),options:t.logger||{}}),u.success("Installed VSF Logger plugin")),s.e2e&&(this.addPlugin(n.resolve(__dirname,"../plugins/e2e-testing.js")),u.success("Installed Vue Storefront E2E testing plugin")),s.i18nExtension&&(this.addPlugin({src:n.resolve(__dirname,"../plugins/i18n-cookies.js"),options:this.options.i18n}),u.success("Installed Internationalization Cookies plugin")),e.existsSync(l("@storefront-ui/vue"))&&s.sfui&&(h.call(this,s),u.success("Installed StorefrontUI Module")),d.call(this,s),u.success("Installed Performance Module"),g.call(this,s)}export{v as default,m as meta};
2
- //# sourceMappingURL=index.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/helpers/log.ts","../src/helpers/merge.ts","../src/helpers/resolveDependency.ts","../src/modules/performance.ts","../src/modules/storefront-ui.ts","../src/modules/raw-sources-loader.ts","../src/helpers/isProduction.ts","../src/index.ts"],"sourcesContent":["import consola from 'consola';\nimport chalk from 'chalk';\nimport { Log } from '../types';\n\nconst log: Log = Object.freeze({\n info: (message) => consola.info(chalk.bold('VSF'), message),\n success: (message) => consola.success(chalk.bold('VSF'), message),\n warning: (message) => consola.warn(chalk.bold('VSF'), message),\n error: (message) => consola.error(chalk.bold('VSF'), message)\n});\n\nexport default log;\n","import { mergeWith, isArray } from 'lodash';\n\nexport default (source, destination) => mergeWith(source, destination, (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n});\n","export default function resolveDependency(name: string): string {\n try {\n return require.resolve(name, { paths: [process.cwd()] });\n } catch (error) {\n return '';\n }\n}\n","import { merge } from 'lodash';\nimport { ModuleOptions, PurgeCSSOptions } from '../types';\n\nfunction pushScripts(): void {\n this.options.render = merge(this.options.render, {\n http2: {\n push: true,\n pushAssets: (request, response, publicPath, preloadFiles) => {\n return preloadFiles\n .filter(({ asType }) => asType === 'script')\n .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`);\n }\n }\n });\n}\n\nfunction loadPurgeCss(options: PurgeCSSOptions): void {\n // PurgeCSS module should be installed after all other modules\n this.nuxt.hook('modules:done', moduleContainer => moduleContainer.addModule(['nuxt-purgecss', options]));\n}\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n const { httpPush, purgeCSS } = options.performance;\n\n if (httpPush) {\n pushScripts.call(this);\n }\n\n if (purgeCSS && purgeCSS.enabled) {\n loadPurgeCss.call(this, purgeCSS);\n }\n}\n","import merge from '../helpers/merge';\nimport { ModuleOptions } from '../types';\n\n// TODO: Create a separate nuxt module for storefront ui\nfunction loadStorefrontRawSources(options: ModuleOptions): void {\n const rawSources = [\n '@storefront-ui/vue',\n '@storefront-ui/shared'\n ];\n\n options.useRawSource = merge(options.useRawSource, {\n dev: rawSources,\n prod: rawSources\n });\n}\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n loadStorefrontRawSources.call(this, options);\n}\n","import log from '../helpers/log';\nimport isProduction from '../helpers/isProduction';\nimport resolveDependency from '../helpers/resolveDependency';\nimport { ModuleOptions } from '../types';\n\nexport default function VueStorefrontPerformanceModule(options: ModuleOptions): void {\n const useRawSource = (pckg) => {\n const pkgPath = resolveDependency(`${pckg}/package.json`);\n // eslint-disable-next-line global-require\n const pkg = require(pkgPath || '');\n\n if (pkg.module) {\n this.extendBuild(config => {\n config.resolve.alias[pkg.name + '$'] = resolveDependency(`${pckg}/${pkg.module}`);\n });\n }\n\n this.options.build.transpile.push(pckg);\n log.info(`Using raw source/ESM for ${pkg.name}`);\n };\n\n options.useRawSource[isProduction(options) ? 'prod' : 'dev'].map(pckg => useRawSource(pckg));\n}\n","import { ModuleOptions } from '../types';\n\nexport default (options: ModuleOptions): boolean => process.env.NODE_ENV === 'production' || options.coreDevelopment;\n","// TODO proper bundling, for now it's just to experiment with nuxt modules api\nimport fs from 'fs';\nimport path from 'path';\nimport log from './helpers/log';\nimport merge from './helpers/merge';\nimport resolveDependency from './helpers/resolveDependency';\nimport performanceModule from './modules/performance';\nimport storefrontUiModule from './modules/storefront-ui';\nimport rawSourcesModule from './modules/raw-sources-loader';\nimport { ModuleOptions } from './types';\n\nexport { default as meta } from '../package.json';\n\n/**\n * VueStorefrontNuxtModule\n * @param moduleOptions\n */\nexport default function VueStorefrontNuxtModule(moduleOptions: ModuleOptions) {\n const defaultOptions = {\n coreDevelopment: false,\n i18nExtension: true,\n e2e: true,\n logger: true,\n ssr: true,\n context: true,\n sfui: true,\n performance: {\n httpPush: true,\n purgeCSS: {\n enabled: false,\n paths: ['**/*.vue']\n }\n },\n useRawSource: {\n dev: [],\n prod: []\n }\n };\n\n const options = merge(defaultOptions, moduleOptions);\n\n // Add meta data\n this.options.head.meta.push({\n name: 'generator',\n content: 'Vue Storefront 2'\n });\n\n log.info('Starting Vue Storefront Nuxt Module');\n\n // Enable HTTP/2 push for JS files\n if (options.performance.httpPush) {\n this.options.render = merge(this.options.render, {\n http2: {\n push: true,\n pushAssets: (request, response, publicPath, preloadFiles) => {\n return preloadFiles\n .filter(({ asType }) => asType === 'script')\n .map(({ file, asType }) => `<${publicPath}${file}>; rel=preload; as=${asType}`);\n }\n }\n });\n }\n\n if (options.context) {\n // Context plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/context.js'));\n log.success('Installed Vue Storefront Context plugin');\n }\n if (options.ssr) {\n // SSR plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/ssr.js'));\n log.success('Installed Vue Storefront SSR plugin');\n }\n\n if (options.logger) {\n // Logger plugin\n this.addPlugin({\n src: path.resolve(__dirname, '../plugins/logger.js'),\n options: moduleOptions.logger || {}\n });\n log.success('Installed VSF Logger plugin');\n }\n\n if (options.e2e) {\n // Context plugin\n this.addPlugin(path.resolve(__dirname, '../plugins/e2e-testing.js'));\n log.success('Installed Vue Storefront E2E testing plugin');\n }\n\n // i18n-cookies plugin\n if (options.i18nExtension) {\n this.addPlugin({\n src: path.resolve(__dirname, '../plugins/i18n-cookies.js'),\n options: this.options.i18n\n });\n log.success('Installed Internationalization Cookies plugin');\n }\n\n // StorefrontUI module\n if (fs.existsSync(resolveDependency('@storefront-ui/vue')) && options.sfui) {\n storefrontUiModule.call(this, options);\n log.success('Installed StorefrontUI Module');\n }\n\n // Performance module\n performanceModule.call(this, options);\n log.success('Installed Performance Module');\n\n // Raw sources loader\n rawSourcesModule.call(this, options);\n}\n"],"names":["log","Object","freeze","info","message","consola","chalk","bold","success","warning","warn","error","merge","source","destination","mergeWith","objValue","srcValue","isArray","concat","resolveDependency","name","require","resolve","paths","process","cwd","pushScripts","this","options","render","http2","push","pushAssets","request","response","publicPath","preloadFiles","filter","_a","asType","map","file","loadPurgeCss","nuxt","hook","moduleContainer","addModule","VueStorefrontPerformanceModule","performance","httpPush","purgeCSS","call","enabled","loadStorefrontRawSources","rawSources","useRawSource","dev","prod","_this","env","NODE_ENV","coreDevelopment","isProduction","pckg","pkgPath","pkg","module","extendBuild","config","alias","build","transpile","VueStorefrontNuxtModule","moduleOptions","i18nExtension","e2e","logger","ssr","context","sfui","head","meta","content","addPlugin","path","__dirname","src","i18n","fs","existsSync","storefrontUiModule","performanceModule","rawSourcesModule"],"mappings":"6IAIA,IAAMA,EAAWC,OAAOC,OAAO,CAC7BC,KAAM,SAACC,GAAY,OAAAC,EAAQF,KAAKG,EAAMC,KAAK,OAAQ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,OAAGuB,EAAI,uBAAAvB,OAAsBqB,WAM5EX,EAAQkD,UAEVnD,KAAKwD,UAAUC,EAAK9D,QAAQ+D,UAAW,0BACvCtF,EAAIQ,QAAQ,4CAEVqB,EAAQiD,MAEVlD,KAAKwD,UAAUC,EAAK9D,QAAQ+D,UAAW,sBACvCtF,EAAIQ,QAAQ,wCAGVqB,EAAQgD,SAEVjD,KAAKwD,UAAU,CACbG,IAAKF,EAAK9D,QAAQ+D,UAAW,wBAC7BzD,QAAS6C,EAAcG,QAAU,KAEnC7E,EAAIQ,QAAQ,gCAGVqB,EAAQ+C,MAEVhD,KAAKwD,UAAUC,EAAK9D,QAAQ+D,UAAW,8BACvCtF,EAAIQ,QAAQ,gDAIVqB,EAAQ8C,gBACV/C,KAAKwD,UAAU,CACbG,IAAKF,EAAK9D,QAAQ+D,UAAW,8BAC7BzD,QAASD,KAAKC,QAAQ2D,OAExBxF,EAAIQ,QAAQ,kDAIViF,EAAGC,WAAWtE,EAAkB,wBAA0BS,EAAQmD,OACpEW,EAAmBvC,KAAKxB,KAAMC,GAC9B7B,EAAIQ,QAAQ,kCAIdoF,EAAkBxC,KAAKxB,KAAMC,GAC7B7B,EAAIQ,QAAQ,gCAGZqF,EAAiBzC,KAAKxB,KAAMC"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Core Vue Storefront 2 nuxt module.
3
- *
4
- * @remarks
5
- * The `@vue-storefront/nuxt` library is responsible for loading core nuxt plugins.
6
- *
7
- * @packageDocumentation
8
- */
9
- export { default as VueStorefrontNuxtModule } from './index';
10
- export { ModuleOptions } from './types';
@@ -1,3 +0,0 @@
1
- import { ModuleOptions } from '../types';
2
- declare const _default: (options: ModuleOptions) => boolean;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { Log } from '../types';
2
- declare const log: Log;
3
- export default log;
@@ -1,2 +0,0 @@
1
- declare const _default: (source: any, destination: any) => any;
2
- export default _default;
@@ -1 +0,0 @@
1
- export default function resolveDependency(name: string): string;
@@ -1,7 +0,0 @@
1
- import { ModuleOptions } from './types';
2
- export { default as meta } from '../package.json';
3
- /**
4
- * VueStorefrontNuxtModule
5
- * @param moduleOptions
6
- */
7
- export default function VueStorefrontNuxtModule(moduleOptions: ModuleOptions): void;
@@ -1,2 +0,0 @@
1
- import { ModuleOptions } from '../types';
2
- export default function VueStorefrontPerformanceModule(options: ModuleOptions): void;
@@ -1,2 +0,0 @@
1
- import { ModuleOptions } from '../types';
2
- export default function VueStorefrontPerformanceModule(options: ModuleOptions): void;
@@ -1,2 +0,0 @@
1
- import { ModuleOptions } from '../types';
2
- export default function VueStorefrontPerformanceModule(options: ModuleOptions): void;
@@ -1,27 +0,0 @@
1
- export interface PurgeCSSOptions {
2
- enabled?: boolean;
3
- paths?: string[];
4
- }
5
- export interface ModuleOptions {
6
- coreDevelopment?: boolean;
7
- i18nExtension?: boolean;
8
- e2e?: boolean;
9
- logger?: boolean;
10
- ssr?: boolean;
11
- context?: boolean;
12
- sfui?: boolean;
13
- performance?: {
14
- httpPush?: boolean;
15
- purgeCSS?: PurgeCSSOptions;
16
- };
17
- useRawSource?: {
18
- dev: string[];
19
- prod: string[];
20
- };
21
- }
22
- export interface Log {
23
- info: (message: string) => void;
24
- success: (message: string) => void;
25
- warning: (message: string) => void;
26
- error: (message: string) => void;
27
- }
@@ -1,17 +0,0 @@
1
- import { configureContext } from '@vue-storefront/core';
2
- import { useContext as useBaseContext } from '@nuxtjs/composition-api';
3
-
4
- const contextPlugin = (ctx, inject) => {
5
- const sharedMap = new Map();
6
-
7
- const useVSFContext = () => {
8
- const { $vsf, ...context } = useBaseContext();
9
-
10
- return { $vsf, ...context, ...$vsf };
11
- };
12
-
13
- configureContext({ useVSFContext });
14
- inject('sharedRefsMap', sharedMap);
15
- };
16
-
17
- export default contextPlugin;
@@ -1,13 +0,0 @@
1
- import Vue from 'vue';
2
-
3
- const e2eTestingPlugin = (ctx) => {
4
- Vue.directive('e2e', {
5
- bind: (element, binding) => {
6
- const enabled = ctx.isDev || ctx.env.NUXT_ENV_E2E === true.toString();
7
-
8
- return enabled && element.setAttribute('data-e2e', binding.value);
9
- }
10
- });
11
- };
12
-
13
- export default e2eTestingPlugin;
@@ -1,116 +0,0 @@
1
- import { i18nRedirectsUtil, VSF_COUNTRY_COOKIE, VSF_CURRENCY_COOKIE, VSF_LOCALE_COOKIE } from '@vue-storefront/core';
2
-
3
- const i18nCookiesPlugin = ({ $cookies, i18n, app, redirect }) => {
4
- const i18nOptions = <%= serialize(options) %>;
5
- const isServer = typeof window === 'undefined';
6
- const navigator = isServer ? undefined : window.navigator;
7
- const acceptedLanguage = app.context.req?.headers?.['accept-language'] || navigator?.languages || '';
8
- const isRouteValid = !!app.context.route.name;
9
- const autoRedirectByLocale = i18nOptions.autoRedirectByLocale ?? true;
10
- const reloadOnLanguageChange = i18nOptions.reloadOnLanguageChange ?? true;
11
- const cookieNames = {
12
- currency: i18nOptions.cookies?.currencyCookieName || VSF_CURRENCY_COOKIE,
13
- country: i18nOptions.cookies?.countryCookieName || VSF_COUNTRY_COOKIE,
14
- locale: i18nOptions.cookies?.localeCookieName || VSF_LOCALE_COOKIE
15
- }
16
- const cookieLocale = $cookies.get(cookieNames.locale);
17
- const cookieCurrency = $cookies.get(cookieNames.currency);
18
- const cookieCountry = $cookies.get(cookieNames.country);
19
- const autoChangeCookie = {
20
- locale: true,
21
- currency: true,
22
- country: true,
23
- ...i18nOptions.autoChangeCookie,
24
- };
25
-
26
- const getDefaultLocale = () => app.$config.defaultLocale;
27
- const getDefaultCurrency = () => app.$config.defaultCurrency;
28
- const getDefaultCountry = () => app.$config.defaultCountry;
29
-
30
- const getCurrencyByLocale = (locale) =>
31
- i18n.numberFormats?.[locale]?.currency?.currency
32
- || i18nOptions.currency
33
- || (i18nOptions.currencies.length && i18nOptions.currencies[0].name);
34
-
35
-
36
- const utils = i18nRedirectsUtil({
37
- path: app.context.route.path,
38
- defaultLocale: getDefaultLocale() ?? i18nOptions.defaultLocale,
39
- availableLocales: i18nOptions.locales.map((item) => item.code),
40
- acceptedLanguages: isServer ? acceptedLanguage.split(',').map((item) => item.split(';')[0]) : acceptedLanguage,
41
- cookieLocale,
42
- autoRedirectByLocale
43
- });
44
-
45
- const targetLocale = utils.getTargetLocale();
46
- const redirectPath = utils.getRedirectPath();
47
-
48
- if (!isRouteValid) {
49
- app.i18n.setLocale(targetLocale);
50
- }
51
-
52
- if (isServer) {
53
- app.i18n.cookieValues = {
54
- ...(autoChangeCookie.locale && { [cookieNames.locale]: targetLocale }),
55
- ...(autoChangeCookie.currency && { [cookieNames.currency]: getDefaultCurrency() || getCurrencyByLocale(targetLocale) })
56
- };
57
-
58
- if (autoRedirectByLocale && redirectPath) {
59
- redirect(redirectPath);
60
- }
61
-
62
- return;
63
- }
64
- const cookieOptions = {
65
- path: '/',
66
- sameSite: 'lax',
67
- expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), // Year from now
68
- ...i18nOptions.cookieOptions
69
- };
70
- const settings = {
71
- locale: targetLocale,
72
- currency: getDefaultCurrency() || getCurrencyByLocale(targetLocale),
73
- country: getDefaultCountry() || i18nOptions.country || (i18nOptions.countries.length && i18nOptions.countries[0].name)
74
- };
75
-
76
- const missingFields = Object
77
- .entries(settings)
78
- .reduce((carry, [name, value]) => {
79
- return [
80
- ...carry,
81
- ...(!value ? [name] : [])
82
- ]
83
- }, []);
84
-
85
- if (missingFields.length) {
86
- throw new Error(`Following fields are missing in the i18n configuration: ${missingFields.join(', ')}`);
87
- }
88
-
89
- if ((cookieLocale !== settings.locale && autoChangeCookie.locale) || !cookieLocale) {
90
- $cookies.set(cookieNames.locale, settings.locale, cookieOptions);
91
- }
92
-
93
- if ((cookieCurrency !== settings.currency && autoChangeCookie.currency) || !cookieCurrency) {
94
- $cookies.set(cookieNames.currency, settings.currency, cookieOptions);
95
- }
96
-
97
- if ((cookieCountry !== settings.country && autoChangeCookie.country) || !cookieCountry) {
98
- $cookies.set(cookieNames.country, settings.country, cookieOptions);
99
- }
100
-
101
- i18n.onBeforeLanguageSwitch = (oldLocale, newLocale, isInitialSetup, context) => {
102
- if (autoChangeCookie.locale) {
103
- $cookies.set(cookieNames.locale, newLocale, cookieOptions);
104
- }
105
-
106
- if (autoChangeCookie.currency) {
107
- $cookies.set(cookieNames.currency, getDefaultCurrency() || getCurrencyByLocale(newLocale), cookieOptions);
108
- }
109
-
110
- if (reloadOnLanguageChange) {
111
- window.location.href = context.route.fullPath;
112
- }
113
- }
114
- }
115
-
116
- export default i18nCookiesPlugin;
package/plugins/logger.js DELETED
@@ -1,8 +0,0 @@
1
- import { registerLogger } from '@vue-storefront/core'
2
-
3
- const loggerPlugin = (ctx) => {
4
- const { verbosity, customLogger, ...args } = <%= serialize(options) %>;
5
- registerLogger(customLogger || args, verbosity || 'error')
6
- };
7
-
8
- export default loggerPlugin;
package/plugins/ssr.js DELETED
@@ -1,31 +0,0 @@
1
- import { configureSSR } from '@vue-storefront/core';
2
- import { ssrRef, getCurrentInstance, onServerPrefetch } from '@nuxtjs/composition-api';
3
-
4
- const hasRouteChanged = (ctx) => {
5
- const { from } = ctx.proxy.$router.app.context;
6
- const { current } = ctx.proxy.$router.history;
7
-
8
- if (!from) {
9
- return false;
10
- }
11
-
12
- return from.fullPath !== current.fullPath;
13
- };
14
-
15
- const ssrPlugin = () => {
16
- configureSSR({
17
- vsfRef: ssrRef,
18
- onSSR: (fn) => {
19
- onServerPrefetch(fn);
20
- if (typeof window !== 'undefined') {
21
- const vm = getCurrentInstance();
22
-
23
- if (hasRouteChanged(vm)) {
24
- fn();
25
- }
26
- }
27
- }
28
- });
29
- };
30
-
31
- export default ssrPlugin;