Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint:
strategy:
matrix:
node-version: [16]
node-version: [18]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -20,7 +20,7 @@ jobs:
test:
strategy:
matrix:
node-version: [16, 17, 18, 19, 20]
node-version: [18, 19, 20, 21, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
build-example-next-contentlayer-example:
strategy:
matrix:
node-version: [18, 19, 20]
node-version: [18, 20, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -43,7 +43,7 @@ jobs:
build-example-next-rsc-dynamic-example:
strategy:
matrix:
node-version: [18, 19, 20]
node-version: [18, 20, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -55,7 +55,7 @@ jobs:
build-example-next-images-example:
strategy:
matrix:
node-version: [18, 19, 20]
node-version: [18, 20, 22]
# TODO re-enable windows
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
Expand All @@ -69,7 +69,7 @@ jobs:
build-example-node-script:
strategy:
matrix:
node-version: [16, 17, 18, 19, 20]
node-version: [18, 19, 20, 21, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -81,7 +81,7 @@ jobs:
build-example-node-script-mdx:
strategy:
matrix:
node-version: [16, 17, 18, 19, 20]
node-version: [18, 19, 20, 21, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -93,7 +93,7 @@ jobs:
build-example-node-script-remote-content:
strategy:
matrix:
node-version: [16, 17, 18, 19, 20]
node-version: [18, 19, 20, 21, 22]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions examples/archive/playground-azimuth-colocated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"contentlayer": "workspace:*",
"contentlayer-stackbit-yaml-generator": "workspace:*",
"next-contentlayer": "workspace:*",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
4 changes: 2 additions & 2 deletions examples/archive/playground-azimuth-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"contentlayer": "workspace:*",
"contentlayer-stackbit-yaml-generator": "workspace:*",
"next-contentlayer": "workspace:*",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
4 changes: 2 additions & 2 deletions examples/archive/playground-azimuth-sanity/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/react-helmet": "^6.1.5",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
4 changes: 2 additions & 2 deletions examples/archive/playground-azimuth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"contentlayer": "workspace:*",
"contentlayer-stackbit-yaml-generator": "workspace:*",
"next-contentlayer": "workspace:*",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
4 changes: 2 additions & 2 deletions examples/archive/playground-contentful-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"contentlayer": "latest",
"next-contentlayer": "latest",
"rehype-highlight": "^5.0.2",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
4 changes: 2 additions & 2 deletions examples/archive/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"contentlayer": "latest",
"next-contentlayer": "latest",
"rehype-highlight": "^5.0.2",
"typescript": "^4.7.4"
"typescript": "^5.5.0"
}
}
}
2 changes: 1 addition & 1 deletion examples/next-contentlayer-example
2 changes: 1 addition & 1 deletion examples/next-images/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"autoprefixer": "^10.4.14",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2",
"typescript": "5.1.6"
"typescript": "^5.5.0"
}
}
2 changes: 1 addition & 1 deletion examples/next-rsc-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"autoprefixer": "^10.4.14",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2",
"typescript": "5.1.6"
"typescript": "^5.5.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint-plugin-simple-import-sort": "^12.1.0",
"prettier": "^3.2.5",
"ts-patch": "^2.1.0",
"typescript": "^5.1.6"
"typescript": "^5.5.0"
},
"resolutions": {
"esbuild": "0.18.0",
Expand Down
33 changes: 19 additions & 14 deletions packages/@contentlayer/core/src/generation/generate-dotpkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,21 @@ const writeFilesForCache = ({
T.succeedWith(() => process.versions.node.split('.').map((_) => parseInt(_, 10)) as [number, number, number]),
)

// NOTE Type assert statements for `.json` files are neccessary from Node v16.14 onwards
const needsJsonAssertStatement = nodeVersionMajor > 16 || (nodeVersionMajor === 16 && nodeVersionMinor >= 14)
const assertStatement = needsJsonAssertStatement ? ` assert { type: 'json' }` : ''
// NOTE: Use import attribute for `.json` files for node v18.20 and node v20.10onwards.
const needsJsonimportAttributeStatement =
nodeVersionMajor > 20 ||
(nodeVersionMajor === 18 && nodeVersionMinor >= 20) ||
(nodeVersionMajor === 20 && nodeVersionMinor >= 10)
const importAttributeStatement = needsJsonimportAttributeStatement
? ` with { type: 'json' }`
: ` assert { type: 'json' }`

const typeNameField = generationOptions.options.fieldOptions.typeFieldName
const dataBarrelFiles = documentDefs.map((docDef) => ({
content: makeDataExportFile({
docDef,
documentIds: allDocuments.filter((_) => _[typeNameField] === docDef.name).map((_) => _._id),
assertStatement,
importAttributeStatement,
}),
filePath: withPrefix('generated', docDef.name, `_index.mjs`),
}))
Expand Down Expand Up @@ -255,7 +260,7 @@ const writeFilesForCache = ({
filePath: withPrefix('generated', 'index.mjs'),
content: makeIndexMjs({
schemaDef,
assertStatement,
importAttributeStatement,
bundleFilePath: relativeBundleFilePath,
isDev,
options,
Expand Down Expand Up @@ -338,19 +343,19 @@ const writeFileWithWrittenFilesCache =
const makeDataExportFile = ({
docDef,
documentIds,
assertStatement,
importAttributeStatement,
}: {
docDef: DocumentTypeDef
documentIds: string[]
assertStatement: string
importAttributeStatement: string
}): string => {
const dataVariableName = getDataVariableName({ docDef })

if (docDef.isSingleton) {
const documentId = documentIds[0]!
return `\
// ${autogeneratedNote}
export { default as ${dataVariableName} } from './${idToFileName(documentId)}.json'${assertStatement}
export { default as ${dataVariableName} } from './${idToFileName(documentId)}.json'${importAttributeStatement}
`
}

Expand All @@ -376,7 +381,7 @@ export { default as ${dataVariableName} } from './${idToFileName(documentId)}.js
)

const docImports = documentIds
.map((_) => `import ${idToVariableNameMap.get(_)} from './${idToFileName(_)}.json'${assertStatement}`)
.map((_) => `import ${idToVariableNameMap.get(_)} from './${idToFileName(_)}.json'${importAttributeStatement}`)
.join('\n')

return `\
Expand All @@ -390,13 +395,13 @@ export const ${dataVariableName} = [${Array.from(idToVariableNameMap.values()).j

const makeIndexMjs = ({
schemaDef,
assertStatement,
importAttributeStatement,
bundleFilePath,
options,
isDev,
}: {
schemaDef: SchemaDef
assertStatement: string
importAttributeStatement: string
bundleFilePath: RelativePosixFilePath
options: PluginOptions
isDev: boolean
Expand All @@ -413,7 +418,7 @@ const makeIndexMjs = ({
.map(({ documentDefName, dataVariableName }) =>
isDev
? `import { ${dataVariableName} } from './${documentDefName}/_index.mjs'`
: `import ${dataVariableName} from './${documentDefName}/_index.json'${assertStatement}`,
: `import ${dataVariableName} from './${documentDefName}/_index.json'${importAttributeStatement}`,
)
.join('\n')

Expand All @@ -434,7 +439,7 @@ export const fetchContent = async (sourceKey) => {
const worker = new Worker(workerFilePath, { workerData: { sourceKey } })

return new Promise((resolve, reject) => {
worker.on('message', (data) => {
worker.on('message', (data) => {
if (data.result) {
resolve(data.result)
} else if (data.fatalError) {
Expand Down Expand Up @@ -485,7 +490,7 @@ export const makeDataTypes = ({ schemaDef, options }: { schemaDef: SchemaDef; op
if (options.experimental.enableDynamicBuild === false) return ''

return `\
export type FetchContentResult =
export type FetchContentResult =
| { _tag: 'Error', error: SourceProvideSchemaErrorJSON | SourceFetchDataErrorJSON }
| { _tag: 'Data', data: DataExports }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
stackbitVersion: ~0.5.0
ssgName: nextjs
cmsName: git
nodeVersion: "16"
nodeVersion: "18"
dataDir: content/data
pagesDir: content/pages
pageLayoutKey: type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
stackbitVersion: ~0.5.0
cmsName: git
ssgName: nextjs
nodeVersion: '16'
nodeVersion: '8'
dataDir: content/data
pagesDir: content/pages
pageLayoutKey: type
Expand Down
2 changes: 1 addition & 1 deletion packages/contentlayer-stackbit-yaml-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"devDependencies": {
"contentlayer2": "workspace:*",
"typescript": "^5.1.6",
"typescript": "^5.5.0",
"vite": "^5.0.12",
"vitest": "1.2.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
// If we still need to use the vitest 0.12.10
// See README.md for more information why this is needed
// threads: false,
deps: {
moduleDirectories: ['node_modules', path.resolve('../../packages')],
},
Expand Down
71 changes: 36 additions & 35 deletions packages/contentlayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,44 @@ Since **contentlayer2** doesn't have any breaking API changes, hopefully this is

1. Replace any Contentlayer packages in your **package.json** with the corresponding fork package and [new version](https://github.com/timlrx/contentlayer2/releases)

```diff
- "contentlayer": "^0.3.3",
+ "contentlayer2": "^0.4.6",
- "next-contentlayer": "^0.3.3",
+ "next-contentlayer2": "^0.4.6",
```
```diff
- "contentlayer": "^0.3.3",
+ "contentlayer2": "^0.4.6",
- "next-contentlayer": "^0.3.3",
+ "next-contentlayer2": "^0.4.6",
```

2. Update any existing imports to the fork packages

**contentlayer.config.ts**
```diff
-import { defineDocumentType, makeSource } from 'contentlayer/source-files';
+import { defineDocumentType, makeSource } from 'contentlayer2/source-files';
```

**next.config.js**
```diff
-const { withContentlayer } = require('next-contentlayer');
+const { withContentlayer } = require('next-contentlayer2');
```
3. Update any package scripts to reference the new `contentlayer2` executable

**package.json**
```diff
{
"scripts": {
- "build:content": "contentlayer build",
+ "build:content": "contentlayer2 build",
}
}
```
**contentlayer.config.ts**

```diff
-import { defineDocumentType, makeSource } from 'contentlayer/source-files';
+import { defineDocumentType, makeSource } from 'contentlayer2/source-files';
```

**next.config.js**

```diff
-const { withContentlayer } = require('next-contentlayer');
+const { withContentlayer } = require('next-contentlayer2');
```

3. Update any package scripts to reference the new `contentlayer2` executable

**package.json**

```diff
{
"scripts": {
- "build:content": "contentlayer build",
+ "build:content": "contentlayer2 build",
}
}
```

4. Run a `contentlayer2 build` and start your **Next.js** application. If you don't see any errors, you're likely good to go! 🥳

Otherwise, see below for common compatibility issues. ❤️‍🩹

#### Upgrading incompatible Remark and Rehype packages
Expand All @@ -87,6 +87,7 @@ If you can't or don't want to upgrade to TypeScript 5+ yet, you can use your pac
- For **Yarn** use the [`resolutions`](https://yarnpkg.com/configuration/manifest#resolutions) field

### Tutorial & Documentation

Follow [the tutorial](https://www.contentlayer.dev/docs/getting-started) to get started building your own project. Or explore [the full documentation](https://www.contentlayer.dev/docs).
Follow [the tutorial](https://www.contentlayer.dev/docs/getting-started) to get started building your own project. Or explore [the full documentation](https://www.contentlayer.dev/docs).

Expand Down
Loading