Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic absolute path import for Windows fix#477 #571

Closed
wants to merge 2 commits into from

Conversation

aolyang
Copy link

@aolyang aolyang commented Oct 20, 2023

this PR fix issue #477

according to nodejs/node#31710 and https://nodejs.org/api/url.html#url_url_pathtofileurl_path

import { pathToFileURL } from 'node:url';

new URL('/foo#1', 'file:');           // Incorrect: file:///foo#1
pathToFileURL('/foo#1');              // Correct:   file:///foo%231 (POSIX)

new URL('/some/path%.c', 'file:');    // Incorrect: file:///some/path%.c
pathToFileURL('/some/path%.c');       // Correct:   file:///some/path%25.c (POSIX)

steps

  1. test the fixture is right by npm patch package.
  2. fork and install, follow CONTRIBUTING.md
  3. change next-contentlyer-example/contentlayer.config.ts add onSuccess hook
    export default makeSource({
      contentDirPath: 'posts',
      documentTypes: [Post],
    +  onSuccess: async (importData) => {
    +    const { allDocuments } = await importData()
    +    console.log('Contentlayer data successfully generated.', allDocuments.length)
    +  }
    })
  4. build next-contentlyer-example with no change, error occur.
    image
  5. update packages\@contentlayer\core\src\generation\generate-dotpkg.ts, yarn build at root dir.
  6. rebuild success;
  7. test again on Debian linux.

win bash
image

debian
image

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2023

⚠️ No Changeset found

Latest commit: 35ee674

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "examples-*" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

remove unnecessary indent change by auto lint
@PxlSyl
Copy link

PxlSyl commented Nov 5, 2023

Hi, same error here. Will it be fixed soon?

@aolyang
Copy link
Author

aolyang commented Nov 5, 2023

@PxlSyl follow this issue can help you timlrx/tailwind-nextjs-starter-blog#704

Im not sure when this PR will be accepted.

@DemuraAIdev
Copy link

Accept pls

Copy link

stale bot commented Nov 28, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Nov 28, 2023
@stale stale bot closed this Dec 5, 2023
@rreo
Copy link

rreo commented Dec 16, 2023

Why was this closed?

@timlrx
Copy link

timlrx commented Apr 23, 2024

@aolyang I have merged the fix in timlrx/contentlayer2#7. Feel free to try out v0.4.5 of contentlayer2 and let me know if it now works well in Windows, thanks!

@aolyang
Copy link
Author

aolyang commented May 11, 2024

git clone https://github.com/aolyang/blogs.git contentlayer2-test --depth=1 # currently contentlayer version
cd contentlayer2-test
pnpm i
pnpm dev # it's fixed by patched, works

Then pnpm patch-remove @contentlayer/[email protected] undo the fix.

Don't forget remove .contentlayer directory (caches), and errors back.

image

pnpm rm contentlayer next-contentlayer -r
pnpm add contentlayer@npm:contentlayer2 `
>          next-contentlayer@npm:next-contentlayer2 `
>          -D
pnpm dev

URL error is gone (if I not use mdx frontmatter), but another problem appear, stucked by timlrx/contentlayer2#15

I will try it latter if the problem fixed.

Say somthing complaint, dont be mind.
Currently, self package-pathces is good to go.
This code base use effect-ts compose logic, and so many short name alias.
Codes and Effect-ts is good if learn it through standlone function, but block me maybe others too from mid journey of this repo.
And not that active. (maybe) 🤣
And not that willing to accept PR.
Maybe abondon this ship, try Nextra or Astro is another good chice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants