canopycms-next 0.0.18 → 0.0.20

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.
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/config.ts
31
+ var config_exports = {};
32
+ __export(config_exports, {
33
+ withCanopy: () => withCanopy
34
+ });
35
+ module.exports = __toCommonJS(config_exports);
36
+
37
+ // src/with-canopy.ts
38
+ var import_node_module = require("node:module");
39
+ var import_node_path = __toESM(require("node:path"), 1);
40
+ var REQUIRED_PACKAGES = ["canopycms"];
41
+ var OPTIONAL_PACKAGES = [
42
+ "canopycms-next",
43
+ "canopycms-auth-clerk",
44
+ "canopycms-auth-dev",
45
+ "canopycms-cdk"
46
+ ];
47
+ var CMS_PAGE_EXTENSIONS = ["server.ts", "server.tsx"];
48
+ var NEXTJS_DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
49
+ function resolveReactAliases(resolve) {
50
+ try {
51
+ return {
52
+ react: import_node_path.default.dirname(resolve("react")),
53
+ "react-dom": import_node_path.default.dirname(resolve("react-dom"))
54
+ };
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+ function withCanopy(nextConfig = {}, options = {}) {
60
+ const resolve = (0, import_node_module.createRequire)(import_node_path.default.join(process.cwd(), "noop.js")).resolve;
61
+ const installedOptional = OPTIONAL_PACKAGES.filter((pkg) => {
62
+ try {
63
+ resolve(pkg);
64
+ return true;
65
+ } catch {
66
+ return false;
67
+ }
68
+ });
69
+ const existingPackages = nextConfig.transpilePackages ?? [];
70
+ const allPackages = [
71
+ .../* @__PURE__ */ new Set([
72
+ ...existingPackages,
73
+ ...REQUIRED_PACKAGES,
74
+ ...installedOptional,
75
+ ...options.packages ?? []
76
+ ])
77
+ ];
78
+ const reactAlias = resolveReactAliases(resolve);
79
+ const existingWebpack = nextConfig.webpack;
80
+ const webpack = reactAlias ? (config, ctx) => {
81
+ config.module = config.module ?? { rules: [] };
82
+ config.module.rules = config.module.rules ?? [];
83
+ config.module.rules.push({
84
+ test: /\.(?:ts|tsx|js|jsx|mjs)$/,
85
+ include: /[\\/]canopycms/,
86
+ resolve: {
87
+ alias: reactAlias
88
+ }
89
+ });
90
+ if (typeof existingWebpack === "function") {
91
+ return existingWebpack(config, ctx);
92
+ }
93
+ return config;
94
+ } : existingWebpack;
95
+ const pageExtensions = options.staticBuild ? nextConfig.pageExtensions : [...nextConfig.pageExtensions ?? NEXTJS_DEFAULT_PAGE_EXTENSIONS, ...CMS_PAGE_EXTENSIONS];
96
+ return {
97
+ ...nextConfig,
98
+ transpilePackages: allPackages,
99
+ ...pageExtensions ? { pageExtensions } : {},
100
+ webpack
101
+ };
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ withCanopy
106
+ });
@@ -0,0 +1,2 @@
1
+ export { withCanopy, type WithCanopyOptions } from './with-canopy';
2
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
package/dist/config.js ADDED
@@ -0,0 +1,2 @@
1
+ export { withCanopy } from './with-canopy';
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAA"}
@@ -0,0 +1,69 @@
1
+ // src/with-canopy.ts
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ var REQUIRED_PACKAGES = ["canopycms"];
5
+ var OPTIONAL_PACKAGES = [
6
+ "canopycms-next",
7
+ "canopycms-auth-clerk",
8
+ "canopycms-auth-dev",
9
+ "canopycms-cdk"
10
+ ];
11
+ var CMS_PAGE_EXTENSIONS = ["server.ts", "server.tsx"];
12
+ var NEXTJS_DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
13
+ function resolveReactAliases(resolve) {
14
+ try {
15
+ return {
16
+ react: path.dirname(resolve("react")),
17
+ "react-dom": path.dirname(resolve("react-dom"))
18
+ };
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ function withCanopy(nextConfig = {}, options = {}) {
24
+ const resolve = createRequire(path.join(process.cwd(), "noop.js")).resolve;
25
+ const installedOptional = OPTIONAL_PACKAGES.filter((pkg) => {
26
+ try {
27
+ resolve(pkg);
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ });
33
+ const existingPackages = nextConfig.transpilePackages ?? [];
34
+ const allPackages = [
35
+ .../* @__PURE__ */ new Set([
36
+ ...existingPackages,
37
+ ...REQUIRED_PACKAGES,
38
+ ...installedOptional,
39
+ ...options.packages ?? []
40
+ ])
41
+ ];
42
+ const reactAlias = resolveReactAliases(resolve);
43
+ const existingWebpack = nextConfig.webpack;
44
+ const webpack = reactAlias ? (config, ctx) => {
45
+ config.module = config.module ?? { rules: [] };
46
+ config.module.rules = config.module.rules ?? [];
47
+ config.module.rules.push({
48
+ test: /\.(?:ts|tsx|js|jsx|mjs)$/,
49
+ include: /[\\/]canopycms/,
50
+ resolve: {
51
+ alias: reactAlias
52
+ }
53
+ });
54
+ if (typeof existingWebpack === "function") {
55
+ return existingWebpack(config, ctx);
56
+ }
57
+ return config;
58
+ } : existingWebpack;
59
+ const pageExtensions = options.staticBuild ? nextConfig.pageExtensions : [...nextConfig.pageExtensions ?? NEXTJS_DEFAULT_PAGE_EXTENSIONS, ...CMS_PAGE_EXTENSIONS];
60
+ return {
61
+ ...nextConfig,
62
+ transpilePackages: allPackages,
63
+ ...pageExtensions ? { pageExtensions } : {},
64
+ webpack
65
+ };
66
+ }
67
+ export {
68
+ withCanopy
69
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { createCanopyCatchAllHandler, wrapNextRequest, type CanopyNextOptions } from './adapter';
2
2
  export { createNextCanopyContext, type NextCanopyOptions, type NextCanopyContextResult, } from './context-wrapper';
3
3
  export { createMockAuthPlugin, createRejectingAuthPlugin } from './test-utils';
4
- export { withCanopy, type WithCanopyOptions } from './with-canopy';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEhG,OAAO,EACL,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAE9E,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEhG,OAAO,EACL,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { createCanopyCatchAllHandler, wrapNextRequest } from './adapter';
2
2
  export { createNextCanopyContext, } from './context-wrapper';
3
3
  export { createMockAuthPlugin, createRejectingAuthPlugin } from './test-utils';
4
- export { withCanopy } from './with-canopy';
5
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAA0B,MAAM,WAAW,CAAA;AAEhG,OAAO,EACL,uBAAuB,GAGxB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAE9E,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAA0B,MAAM,WAAW,CAAA;AAEhG,OAAO,EACL,uBAAuB,GAGxB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
@@ -47,7 +47,7 @@ export interface WithCanopyOptions {
47
47
  * @example
48
48
  * ```ts
49
49
  * // next.config.ts
50
- * import { withCanopy } from 'canopycms-next'
50
+ * import { withCanopy } from 'canopycms-next/config'
51
51
  *
52
52
  * export default withCanopy({
53
53
  * reactStrictMode: true,
@@ -79,7 +79,7 @@ function resolveReactAliases(resolve) {
79
79
  * @example
80
80
  * ```ts
81
81
  * // next.config.ts
82
- * import { withCanopy } from 'canopycms-next'
82
+ * import { withCanopy } from 'canopycms-next/config'
83
83
  *
84
84
  * export default withCanopy({
85
85
  * reactStrictMode: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopycms-next",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Next.js adapter for CanopyCMS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,12 +14,17 @@
14
14
  "types": "dist/index.d.ts",
15
15
  "exports": {
16
16
  ".": {
17
- "import": "./dist/index.js",
18
- "types": "./dist/index.d.ts"
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
19
  },
20
20
  "./client": {
21
- "import": "./dist/client.js",
22
- "types": "./dist/client.d.ts"
21
+ "types": "./dist/client.d.ts",
22
+ "import": "./dist/client.js"
23
+ },
24
+ "./config": {
25
+ "types": "./dist/config.d.ts",
26
+ "require": "./dist/config.cjs",
27
+ "import": "./dist/config.mjs"
23
28
  }
24
29
  },
25
30
  "files": [
@@ -31,19 +36,20 @@
31
36
  "peerDependencies": {
32
37
  "next": "^13.5.7 || ^14.2.25 || ^15.2.3 || ^16",
33
38
  "react": "^18.0.0 || ^19.0.0",
34
- "canopycms": "0.0.18"
39
+ "canopycms": "0.0.20"
35
40
  },
36
41
  "devDependencies": {
37
42
  "@types/node": "^22.9.0",
43
+ "esbuild": "^0.24.2",
38
44
  "@types/react": "^18.3.12",
39
45
  "next": "^14.2.25",
40
46
  "react": "^18.3.1",
41
47
  "typescript": "^5.6.3",
42
48
  "vitest": "^1.6.0",
43
- "canopycms": "0.0.18"
49
+ "canopycms": "0.0.20"
44
50
  },
45
51
  "scripts": {
46
- "build": "tsc -p tsconfig.build.json",
52
+ "build": "tsc -p tsconfig.build.json && esbuild src/config.ts --bundle --platform=node --packages=external --external:next --format=cjs --outfile=dist/config.cjs && esbuild src/config.ts --bundle --platform=node --packages=external --external:next --format=esm --outfile=dist/config.mjs",
47
53
  "lint": "eslint src/",
48
54
  "test": "vitest run --reporter=dot",
49
55
  "typecheck": "tsc --noEmit"