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

conversion to ESM, and deletion of CommonJS #2106

Merged
merged 5 commits into from
Jul 16, 2023
Merged

conversion to ESM, and deletion of CommonJS #2106

merged 5 commits into from
Jul 16, 2023

Conversation

trusktr
Copy link
Member

@trusktr trusktr commented Jun 25, 2023

Continues from PR

Part of

Summary

Convert to ES Modules. Round two (replaces PR #1689)

What kind of change does this PR introduce?

Code style update
Refactor
Docs
Build-related changes

For any code change,

  • Related documentation has been updated if needed
  • Related tests have been updated or tests have been added

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Applications with build tooling relying on CommonJS may not work anymore. People with no build using the global script method of importing Docsify should not be affected.

Related issue, if any:

#2102

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

@vercel
Copy link

vercel bot commented Jun 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 1 resolved Jul 16, 2023 4:58pm

@trusktr trusktr changed the title initial conversion to ESM initial conversion to ESM, and deletion of CommonJS Jun 25, 2023
@trusktr trusktr linked an issue Jun 25, 2023 that may be closed by this pull request
@trusktr
Copy link
Member Author

trusktr commented Jun 25, 2023

@sy-records looks like build:js fails on Vercel, but it works for me locally. Do you see any issue with build:js?

EDIT: I needed to hit "Redploy" without build cache. Now past that error.

@sy-records
Copy link
Member

> docsify@4.13.0 css
--
15:16:04.346 | > node build/css -o themes
15:16:04.346 |  
15:16:04.402 | file:///vercel/path0/build/css.js:6
15:16:04.402 | fs.readdir(path.join(__dirname, '../src/themes'), (err, files) => {
15:16:04.403 | ^
15:16:04.403 |  
15:16:04.403 | ReferenceError: __dirname is not defined in ES module scope
15:16:04.403 | This file is being treated as an ES module because it has a '.js' file extension and '/vercel/path0/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
15:16:04.403 | at file:///vercel/path0/build/css.js:6:22
15:16:04.403 | at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
15:16:04.403 |  
15:16:04.403 | Node.js v18.15.0
15:16:04.420 | ERROR: "build:css" exited with 1.
15:16:04.432 | npm ERR! code 1
15:16:04.432 | npm ERR! path /vercel/path0
15:16:04.433 | npm ERR! command failed
15:16:04.433 | npm ERR! command sh -c npm run build
15:16:04.434 |  
15:16:04.434 | npm ERR! A complete log of this run can be found in:
15:16:04.435 | npm ERR!     /vercel/.npm/_logs/2023-06-25T07_15_41_968Z-debug-0.log
15:16:04.469 | Error: Command "npm install" exited with 1
15:16:04.960 | BUILD_UTILS_SPAWN_1: Command "npm install" exited with 1


@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 25, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit eb3706c:

Sandbox Source
docsify-template Configuration

@trusktr
Copy link
Member Author

trusktr commented Jun 25, 2023

15:16:04.403 | ReferenceError: __dirname is not defined in ES module scope

Just saw your comment, but I fixed already. :)

It will be nice if we can see builds for all pull requests, because right now the base of this pull request is delete-ssr and this causes the builds to be skipped (f.e. the unit tests).

@trusktr
Copy link
Member Author

trusktr commented Jun 25, 2023

Ok, I updated test.yml, and now all builds are running! Nice!

@trusktr
Copy link
Member Author

trusktr commented Jun 25, 2023

We should add a few more tests that currently do not exists while we're at it, to test for backwards compatibilty. For example:

  • test the website loading Docsify from unpkg to ensure that still works
  • test with cdnjs
  • etc

Basically we want to ensure that all people using the standard <script> are not broken. And this will be only a breaking change for people who have a build setup where they import ... from 'docsify', as some tools might break with the new type:module and exports field in package.json. Most users use <script>, and should not be affected.

@trusktr
Copy link
Member Author

trusktr commented Jun 26, 2023

Tests are almost passing. Darn Windows! Once we're ready, I'll squash with angular commit format.

@trusktr
Copy link
Member Author

trusktr commented Jun 26, 2023

The build is green!

@trusktr
Copy link
Member Author

trusktr commented Jun 26, 2023

Looks like Vue mounts broke? See this page at the very bottom: https://docsify-preview-9clr8ye9a-docsifyjs.vercel.app/?vercelThreadId=sWMyo#/configuration?id=vuemounts

EDIT: nevermind. Looks like it already doesn't work from before. For example, this build,

https://docsify-preview-6nln8n898-docsifyjs.vercel.app/#/configuration?id=vuemounts

for pull request #2093 doesn't work.

@trusktr
Copy link
Member Author

trusktr commented Jun 26, 2023

I pushed one more update to restore deleted example code (I think we should just delete example.test.js files) and ci/codesandbox failed for some reason, but the output looks fine. Looks like a codesandbox bug.

@Koooooo-7
Copy link
Member

I pushed one more update to restore deleted example code (I think we should just delete example.test.js files) and ci/codesandbox failed for some reason, but the output looks fine. Looks like a codesandbox bug.

Some unit test cases put in example.test.js now. We need refine it with meaningful file name later.

@trusktr
Copy link
Member Author

trusktr commented Jun 30, 2023

Some unit test cases put in example.test.js now. We need refine it with meaningful file name later.

Roger! I'll take a look, delete only example tests, keep real tests, and rename the files (or move to existing files).

…in Rollup config because some dependencies are still CommonJS

BREAKING: The new project layout might break in some tooling setups.

We've added an exports field to `package.json` to specify where
statements like `import ... from 'docsify'` will import from, and left
the `main` and `unpkg` fields as-is for backwards compatibility with the
global <script> import method. Most people who use a non-module
`<script>` tag to import Docsify will not notice a difference. Anyone
else who is importing Docsify into a specilized build setup using
`import` statements has a chance of being broken, so we've marked this
as BREAKING.
…ll request and not only for those to main or develop
@trusktr
Copy link
Member Author

trusktr commented Jul 2, 2023

I deleted the unnecessary example tests (left the good ones that were in the example files)

Base automatically changed from delete-ssr to develop July 2, 2023 18:34
@trusktr
Copy link
Member Author

trusktr commented Jul 2, 2023

We should add a few more tests that currently do not exists while we're at it, to test for backwards compatibilty. For example:

  • test the website loading Docsify from unpkg to ensure that still works
  • test with cdnjs
  • etc

Actually we can't really test unpkg or cdnjs without publishing! However, all tests still pass with the global build, and I haven't changed the tests, so this mean everything will work.

When we publish to npm, then https://unpkg.com/docsify or https://unpkg.com/docsify/lib/docsify.min.js will both forward to https://unpkg.com/docsify@5/lib/docsify.min.js, and this will continue to work (same file we use in our tests).

So, all apps using this HTML:

<script src="https://unpkg.com/docsify"></script>

or

<script src="https://unpkg.com/docsify/lib/docsify.min.js"></script>

will not be broken.

Note, as we chatted about previously, there are quite a number of people using the URLs without version numbers:

https://github.com/search?q=https%3A%2F%2Funpkg.com%2Fdocsify&type=code

It looks like CDNjs URLs like https://cdn.jsdelivr.net/npm/docsify/lib/docsify.js will continue to work as well, using the same file structure.

So I think we're good here.


In the modernizing issue, I'll write a task for a new deprecation cycle so that we can get people off of the versionless URLs in a reasonable way without suddenly breaking them.

@trusktr
Copy link
Member Author

trusktr commented Jul 2, 2023

@docsifyjs/core Alright, this is ready to go. Required tests passing (codesandbox build is having a sporadic issue unrelated to Docsify, resource limits being reached, and I currently have no control over that integration that @anikethsaha put in place)

@trusktr trusktr requested review from Koooooo-7 and a team July 3, 2023 09:16
"args": ["--", "-i", "${relativeFile}", "--testPathIgnorePatterns"],
"runtimeExecutable": "npx",
"runtimeArgs": ["jest"],
"args": ["-i", "${relativeFile}", "--testPathIgnorePatterns"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scripts were out of date. Now you can run them in VS Code! Give it a try!

@trusktr
Copy link
Member Author

trusktr commented Jul 16, 2023

Alright, per our Discord convo, its going in!

@trusktr trusktr merged commit c2428f7 into develop Jul 16, 2023
6 checks passed
@trusktr trusktr deleted the es-modules branch July 16, 2023 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of CommonJS module format, use only ES Modules.
3 participants