canopycms-next 0.0.5 → 0.0.6
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 +21 -0
- package/dist/adapter.d.ts +8 -10
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +2 -1
- package/dist/adapter.js.map +1 -1
- package/dist/context-wrapper.d.ts +4 -4
- package/dist/context-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/with-canopy.d.ts +39 -0
- package/dist/with-canopy.d.ts.map +1 -0
- package/dist/with-canopy.js +109 -0
- package/dist/with-canopy.js.map +1 -0
- package/package.json +22 -23
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Rice University
|
|
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/dist/adapter.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type { NextRequest } from 'next/server';
|
|
2
|
-
import { NextResponse } from 'next/server';
|
|
3
1
|
import { type CanopyHandlerOptions, type CanopyRequest } from 'canopycms/http';
|
|
4
2
|
/**
|
|
5
3
|
* Options for creating a Canopy Next.js handler.
|
|
6
4
|
* Same as core CanopyHandlerOptions - re-exported for convenience.
|
|
7
5
|
*/
|
|
8
|
-
export
|
|
9
|
-
}
|
|
6
|
+
export type CanopyNextOptions = CanopyHandlerOptions;
|
|
10
7
|
/**
|
|
11
|
-
* Wrap a
|
|
8
|
+
* Wrap a standard Request (or NextRequest) to implement the CanopyRequest interface.
|
|
9
|
+
* Only uses standard Request methods, so any Request subclass works.
|
|
12
10
|
*/
|
|
13
|
-
export declare function wrapNextRequest(req:
|
|
11
|
+
export declare function wrapNextRequest(req: Request): CanopyRequest;
|
|
14
12
|
/**
|
|
15
13
|
* Catch-all Next.js handler for a single API route (e.g., /api/canopycms/[...canopycms]).
|
|
16
14
|
*
|
|
@@ -38,13 +36,13 @@ export declare function wrapNextRequest(req: NextRequest): CanopyRequest;
|
|
|
38
36
|
* export const DELETE = handler
|
|
39
37
|
* ```
|
|
40
38
|
*/
|
|
41
|
-
export declare const createCanopyCatchAllHandler: (options: CanopyNextOptions) => (req:
|
|
39
|
+
export declare const createCanopyCatchAllHandler: (options: CanopyNextOptions) => (req: Request, ctx?: {
|
|
42
40
|
params?: Promise<{
|
|
43
41
|
canopycms?: string[];
|
|
44
|
-
[key: string]:
|
|
42
|
+
[key: string]: unknown;
|
|
45
43
|
}> | {
|
|
46
44
|
canopycms?: string[];
|
|
47
|
-
[key: string]:
|
|
45
|
+
[key: string]: unknown;
|
|
48
46
|
};
|
|
49
|
-
}) => Promise<
|
|
47
|
+
}) => Promise<Response>;
|
|
50
48
|
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAEnB,MAAM,gBAAgB,CAAA;AAEvB;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,CAAA;AAEpD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAkB3D;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,iBAAiB,MAIlE,KAAK,OAAO,EACZ,MAAM;IACJ,MAAM,CAAC,EACH,OAAO,CAAC;QAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,GACzD;QAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CACrD,KACA,OAAO,CAAC,QAAQ,CAMpB,CAAA"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import { createCanopyRequestHandler, } from 'canopycms/http';
|
|
3
3
|
/**
|
|
4
|
-
* Wrap a
|
|
4
|
+
* Wrap a standard Request (or NextRequest) to implement the CanopyRequest interface.
|
|
5
|
+
* Only uses standard Request methods, so any Request subclass works.
|
|
5
6
|
*/
|
|
6
7
|
export function wrapNextRequest(req) {
|
|
7
8
|
return {
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EACL,0BAA0B,GAI3B,MAAM,gBAAgB,CAAA;AAQvB;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,CAAC,GAAG;QAEZ,MAAM,CAAC,IAAY;YACjB,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;QAED,KAAK,CAAC,IAAI;YACR,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK;gBAAE,OAAO,SAAS,CAAA;YAC1C,IAAI,CAAC;gBACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAA;YAClB,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,QAAiC;IACvD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QACtC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,mBAAmB,CAAC,GAElC;IACC,IAAI,CAAC,GAAG,EAAE,MAAM;QAAE,OAAO,EAAE,CAAA;IAC3B,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAA;IACpF,OAAO,CAAC,cAAc,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAC1D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,OAA0B,EAAE,EAAE;IACxE,MAAM,WAAW,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAA;IAEvD,OAAO,KAAK,EACV,GAAY,EACZ,GAIC,EACkB,EAAE;QACrB,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;QACtC,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,GAAG,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QACvD,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -17,15 +17,15 @@ export interface NextCanopyOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function createNextCanopyContext(options: NextCanopyOptions): Promise<{
|
|
19
19
|
getCanopy: () => Promise<CanopyContext>;
|
|
20
|
-
handler: (req:
|
|
20
|
+
handler: (req: Request, ctx?: {
|
|
21
21
|
params?: Promise<{
|
|
22
22
|
canopycms?: string[];
|
|
23
|
-
[key: string]:
|
|
23
|
+
[key: string]: unknown;
|
|
24
24
|
}> | {
|
|
25
25
|
canopycms?: string[];
|
|
26
|
-
[key: string]:
|
|
26
|
+
[key: string]: unknown;
|
|
27
27
|
};
|
|
28
|
-
}) => Promise<
|
|
28
|
+
}) => Promise<Response>;
|
|
29
29
|
services: import("canopycms/server").CanopyServices;
|
|
30
30
|
}>;
|
|
31
31
|
//# sourceMappingURL=context-wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-wrapper.d.ts","sourceRoot":"","sources":["../src/context-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAc,WAAW,EAAE,MAAM,WAAW,CAAA;AA+BlF,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,YAAY,CAAA;IACpB,mGAAmG;IACnG,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAAA;CAC5D;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB;qBAqF1C,OAAO,CAAC,aAAa,CAAC;;
|
|
1
|
+
{"version":3,"file":"context-wrapper.d.ts","sourceRoot":"","sources":["../src/context-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAc,WAAW,EAAE,MAAM,WAAW,CAAA;AA+BlF,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,YAAY,CAAA;IACpB,mGAAmG;IACnG,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAAA;CAC5D;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB;qBAqF1C,OAAO,CAAC,aAAa,CAAC;;cAnE5C,CAAC;qBAA+B,CAAC;;;qBAC3B,CAAC;;;;;GAkFd"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createCanopyCatchAllHandler, wrapNextRequest, type CanopyNextOptions } from './adapter';
|
|
2
2
|
export { createNextCanopyContext, type NextCanopyOptions } from './context-wrapper';
|
|
3
3
|
export { createMockAuthPlugin, createRejectingAuthPlugin } from './test-utils';
|
|
4
|
+
export { withCanopy, type WithCanopyOptions } from './with-canopy';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAAE,uBAAuB,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEnF,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,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,EAAE,uBAAuB,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEnF,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAE9E,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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';
|
|
4
5
|
//# 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,EAAE,uBAAuB,EAA0B,MAAM,mBAAmB,CAAA;AAEnF,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,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,EAAE,uBAAuB,EAA0B,MAAM,mBAAmB,CAAA;AAEnF,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAE9E,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { NextConfig } from 'next';
|
|
2
|
+
export interface WithCanopyOptions {
|
|
3
|
+
/** Additional packages to transpile beyond the Canopy defaults. */
|
|
4
|
+
packages?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Wrap your Next.js config to set up module transpilation and React
|
|
8
|
+
* resolution for CanopyCMS packages.
|
|
9
|
+
*
|
|
10
|
+
* **What it does:**
|
|
11
|
+
* - Adds all Canopy packages to `transpilePackages` (they export raw TypeScript)
|
|
12
|
+
* - Resolves React to a single copy from your project root, preventing
|
|
13
|
+
* dual-instance crashes when using `file:` symlinks for local development
|
|
14
|
+
*
|
|
15
|
+
* **When you need this:**
|
|
16
|
+
* - Always recommended — it replaces manual `transpilePackages` configuration
|
|
17
|
+
* and is harmless when React aliases aren't strictly needed.
|
|
18
|
+
*
|
|
19
|
+
* **When React aliases matter:**
|
|
20
|
+
* - When consuming canopycms packages via `file:` references or `npm link`
|
|
21
|
+
* during local development. Without the aliases, the bundler follows
|
|
22
|
+
* symlinks and may resolve a second copy of React from the linked
|
|
23
|
+
* package's node_modules, causing "Invalid hook call" crashes.
|
|
24
|
+
* - When installing from npm (not symlinked), the aliases are still safe
|
|
25
|
+
* — they simply resolve to the same React your project already uses.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // next.config.ts
|
|
30
|
+
* import { withCanopy } from 'canopycms-next'
|
|
31
|
+
*
|
|
32
|
+
* export default withCanopy({
|
|
33
|
+
* reactStrictMode: true,
|
|
34
|
+
* // ...your config
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function withCanopy(nextConfig?: NextConfig, options?: WithCanopyOptions): NextConfig;
|
|
39
|
+
//# sourceMappingURL=with-canopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-canopy.d.ts","sourceRoot":"","sources":["../src/with-canopy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAYtC,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,UAAU,CACxB,UAAU,GAAE,UAAe,EAC3B,OAAO,GAAE,iBAAsB,GAC9B,UAAU,CA8CZ"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Canopy packages that need transpilation (they export raw TypeScript).
|
|
5
|
+
*/
|
|
6
|
+
const CANOPY_PACKAGES = [
|
|
7
|
+
'canopycms',
|
|
8
|
+
'canopycms-next',
|
|
9
|
+
'canopycms-auth-clerk',
|
|
10
|
+
'canopycms-auth-dev',
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Resolve React modules from the consumer's project root rather than from
|
|
14
|
+
* this package's location. This is critical when canopycms-next is installed
|
|
15
|
+
* via `file:` symlinks — without it, `require.resolve('react')` would walk
|
|
16
|
+
* up from the symlink target and find a different React copy.
|
|
17
|
+
*/
|
|
18
|
+
function resolveReactAliases() {
|
|
19
|
+
try {
|
|
20
|
+
const resolve = createRequire(path.join(process.cwd(), 'noop.js')).resolve;
|
|
21
|
+
// Alias to DIRECTORIES, not files. Webpack uses prefix matching, so
|
|
22
|
+
// aliasing `react` to a directory lets `react/jsx-runtime` resolve
|
|
23
|
+
// to `<dir>/jsx-runtime` naturally. Pointing to a file (index.js)
|
|
24
|
+
// would break subpath resolution (e.g. react/index.js/jsx-runtime).
|
|
25
|
+
return {
|
|
26
|
+
react: path.dirname(resolve('react')),
|
|
27
|
+
'react-dom': path.dirname(resolve('react-dom')),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// If resolution fails (unusual environment), skip aliases.
|
|
32
|
+
// transpilePackages alone may suffice.
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wrap your Next.js config to set up module transpilation and React
|
|
38
|
+
* resolution for CanopyCMS packages.
|
|
39
|
+
*
|
|
40
|
+
* **What it does:**
|
|
41
|
+
* - Adds all Canopy packages to `transpilePackages` (they export raw TypeScript)
|
|
42
|
+
* - Resolves React to a single copy from your project root, preventing
|
|
43
|
+
* dual-instance crashes when using `file:` symlinks for local development
|
|
44
|
+
*
|
|
45
|
+
* **When you need this:**
|
|
46
|
+
* - Always recommended — it replaces manual `transpilePackages` configuration
|
|
47
|
+
* and is harmless when React aliases aren't strictly needed.
|
|
48
|
+
*
|
|
49
|
+
* **When React aliases matter:**
|
|
50
|
+
* - When consuming canopycms packages via `file:` references or `npm link`
|
|
51
|
+
* during local development. Without the aliases, the bundler follows
|
|
52
|
+
* symlinks and may resolve a second copy of React from the linked
|
|
53
|
+
* package's node_modules, causing "Invalid hook call" crashes.
|
|
54
|
+
* - When installing from npm (not symlinked), the aliases are still safe
|
|
55
|
+
* — they simply resolve to the same React your project already uses.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* // next.config.ts
|
|
60
|
+
* import { withCanopy } from 'canopycms-next'
|
|
61
|
+
*
|
|
62
|
+
* export default withCanopy({
|
|
63
|
+
* reactStrictMode: true,
|
|
64
|
+
* // ...your config
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function withCanopy(nextConfig = {}, options = {}) {
|
|
69
|
+
// Merge transpilePackages (deduped)
|
|
70
|
+
const existingPackages = nextConfig.transpilePackages ?? [];
|
|
71
|
+
const allPackages = [
|
|
72
|
+
...new Set([...existingPackages, ...CANOPY_PACKAGES, ...(options.packages ?? [])]),
|
|
73
|
+
];
|
|
74
|
+
const reactAlias = resolveReactAliases();
|
|
75
|
+
// Scope React aliases to only canopycms files using module.rules[].resolve.
|
|
76
|
+
// A global resolve.alias would also override Next.js's own internal React
|
|
77
|
+
// (bundled at next/dist/compiled/react/), breaking its devtools and internals.
|
|
78
|
+
const existingWebpack = nextConfig.webpack;
|
|
79
|
+
const webpack = reactAlias
|
|
80
|
+
? (config, ctx) => {
|
|
81
|
+
config.module = config.module ?? { rules: [] };
|
|
82
|
+
config.module.rules = config.module.rules ?? [];
|
|
83
|
+
// Match canopycms source files by path (covers both symlink and real paths)
|
|
84
|
+
config.module.rules.push({
|
|
85
|
+
test: /\.(?:ts|tsx|js|jsx|mjs)$/,
|
|
86
|
+
include: /[\\/]canopycms/,
|
|
87
|
+
resolve: {
|
|
88
|
+
alias: reactAlias,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
// Chain consumer's existing webpack config
|
|
92
|
+
if (typeof existingWebpack === 'function') {
|
|
93
|
+
return existingWebpack(config, ctx);
|
|
94
|
+
}
|
|
95
|
+
return config;
|
|
96
|
+
}
|
|
97
|
+
: existingWebpack;
|
|
98
|
+
// NOTE: Turbopack's resolveAlias does not support absolute file paths —
|
|
99
|
+
// it prepends './' and treats them as relative imports, which breaks.
|
|
100
|
+
// Until Turbopack supports absolute path aliases, consumers using
|
|
101
|
+
// file: symlinks must use `next dev --webpack` for local development.
|
|
102
|
+
// Turbopack works fine when canopycms is installed from npm (no symlinks).
|
|
103
|
+
return {
|
|
104
|
+
...nextConfig,
|
|
105
|
+
transpilePackages: allPackages,
|
|
106
|
+
webpack,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=with-canopy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-canopy.js","sourceRoot":"","sources":["../src/with-canopy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,WAAW;IACX,gBAAgB;IAChB,sBAAsB;IACtB,oBAAoB;CACrB,CAAA;AAOD;;;;;GAKG;AACH,SAAS,mBAAmB;IAC1B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,oEAAoE;QACpE,mEAAmE;QACnE,kEAAkE;QAClE,oEAAoE;QACpE,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SAChD,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,2DAA2D;QAC3D,uCAAuC;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,UAAU,CACxB,aAAyB,EAAE,EAC3B,UAA6B,EAAE;IAE/B,oCAAoC;IACpC,MAAM,gBAAgB,GAAG,UAAU,CAAC,iBAAiB,IAAI,EAAE,CAAA;IAC3D,MAAM,WAAW,GAAG;QAClB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,gBAAgB,EAAE,GAAG,eAAe,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;KACnF,CAAA;IAED,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAA;IAExC,4EAA4E;IAC5E,0EAA0E;IAC1E,+EAA+E;IAC/E,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAA;IAC1C,MAAM,OAAO,GAA0B,UAAU;QAC/C,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;YACd,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;YAC9C,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAA;YAE/C,4EAA4E;YAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;gBACvB,IAAI,EAAE,0BAA0B;gBAChC,OAAO,EAAE,gBAAgB;gBACzB,OAAO,EAAE;oBACP,KAAK,EAAE,UAAU;iBAClB;aACF,CAAC,CAAA;YAEF,2CAA2C;YAC3C,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;gBAC1C,OAAO,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;QACH,CAAC,CAAC,eAAe,CAAA;IAEnB,wEAAwE;IACxE,sEAAsE;IACtE,kEAAkE;IAClE,sEAAsE;IACtE,2EAA2E;IAE3E,OAAO;QACL,GAAG,UAAU;QACb,iBAAiB,EAAE,WAAW;QAC9B,OAAO;KACR,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canopycms-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Next.js adapter for CanopyCMS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/safeinsights/canopycms.git",
|
|
8
|
+
"url": "git+https://github.com/safeinsights/canopycms.git",
|
|
9
9
|
"directory": "packages/canopycms-next"
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
@@ -13,40 +13,39 @@
|
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
|
-
".":
|
|
17
|
-
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"import": "./dist/client.js",
|
|
22
|
+
"types": "./dist/client.d.ts"
|
|
23
|
+
}
|
|
18
24
|
},
|
|
19
25
|
"files": [
|
|
20
26
|
"dist"
|
|
21
27
|
],
|
|
22
|
-
"publishConfig": {
|
|
23
|
-
"exports": {
|
|
24
|
-
".": {
|
|
25
|
-
"import": "./dist/index.js",
|
|
26
|
-
"types": "./dist/index.d.ts"
|
|
27
|
-
},
|
|
28
|
-
"./client": {
|
|
29
|
-
"import": "./dist/client.js",
|
|
30
|
-
"types": "./dist/client.d.ts"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsc -p tsconfig.build.json",
|
|
36
|
-
"test": "vitest run --reporter=dot",
|
|
37
|
-
"typecheck": "tsc --noEmit"
|
|
38
|
-
},
|
|
39
28
|
"engines": {
|
|
40
29
|
"node": ">=18"
|
|
41
30
|
},
|
|
42
31
|
"peerDependencies": {
|
|
43
|
-
"canopycms": "^0.0.
|
|
32
|
+
"canopycms": "^0.0.6",
|
|
44
33
|
"next": "^13.5.7 || ^14.2.25 || ^15.2.3 || ^16",
|
|
45
34
|
"react": "^18.0.0 || ^19.0.0"
|
|
46
35
|
},
|
|
47
36
|
"devDependencies": {
|
|
48
37
|
"@types/node": "^22.9.0",
|
|
38
|
+
"@types/react": "^18.3.12",
|
|
39
|
+
"canopycms": "^0.0.6",
|
|
40
|
+
"next": "^14.2.25",
|
|
41
|
+
"react": "^18.3.1",
|
|
49
42
|
"typescript": "^5.6.3",
|
|
50
43
|
"vitest": "^1.6.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.build.json",
|
|
47
|
+
"lint": "eslint src/",
|
|
48
|
+
"test": "vitest run --reporter=dot",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
}
|