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

feat(v2): allow init project via npm #3729

Merged
merged 5 commits into from
Nov 16, 2020
Merged

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Nov 11, 2020

Motivation

When executing the release script during testing of #3727, I encountered that using yarn I cannot install all the packages. After some investigation, I realized that there is no such problem with npm, so I think this setting will be useful.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Build packages/docusaurus-init
  2. Run node packages/docusaurus-init/bin/index.js init website-with-npm classic --use-npm
  3. The installation of packages for the new site will happen via npm (not yarn), which will be specified in the output

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: new feature This PR adds a new API or behavior. label Nov 11, 2020
@lex111 lex111 requested a review from slorber as a code owner November 11, 2020 22:58
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 11, 2020
@netlify
Copy link

netlify bot commented Nov 11, 2020

Deploy preview for docusaurus-2 ready!

Built with commit bcac688

https://deploy-preview-3729--docusaurus-2.netlify.app

@lex111
Copy link
Contributor Author

lex111 commented Nov 11, 2020

➤ YN0000: Successfully set enableGlobalCache to true
Usage Error: The nearest package directory (/home/runner/work/docusaurus/docusaurus/test-website) doesn't seem to be part of the project declared in /home/runner/work/docusaurus/docusaurus.

- If the project directory is right, it might be that you forgot to list test-website as a workspace.
- If it isn't, it's likely because you have a yarn.lock or package.json file there, confusing the project root detection.

$ yarn install [--json] [--immutable] [--immutable-cache] [--check-cache] [--inline-builds]
Error: Process completed with exit code 1.

Strange 👀

@slorber
Copy link
Collaborator

slorber commented Nov 12, 2020

Maybe adding it to the workspace would help?

  "workspaces": [
    "packages/*",
    "website",
    "website-1.x",
    "website-1.x-migrated",
    "packages/docusaurus-init/templates/*"
+   "test-website",
  ],

@lex111 lex111 changed the title feat(v2: allow init project via npm feat(v2): allow init project via npm Nov 12, 2020
@lex111 lex111 force-pushed the lex111/npm-flag-init-command branch from 3993b6e to 8e8861e Compare November 12, 2020 12:54
@lex111
Copy link
Contributor Author

lex111 commented Nov 12, 2020

Maybe adding it to the workspace would help?

Done it, but for some unknown reason, the E2E test still falls :(

@slorber
Copy link
Collaborator

slorber commented Nov 12, 2020

don't see the problem, maybe try to revert some parts of the code and see if it improves in any way?

@lex111
Copy link
Contributor Author

lex111 commented Nov 12, 2020

  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR lerna ERR! yarn run build exited 1 in '@docusaurus/init'
  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR lerna ERR! yarn run build stdout:
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(9,16): error TS7016: Could not find a declaration file for module 'fs-extra'. '/home/runner/.yarn/berry/cache/fs-extra-npm-8.1.0-197473387f-7.zip/node_modules/fs-extra/lib/index.js' implicitly has an 'any' type.
  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR   Try `npm install @types/fs-extra` if it exists or add a new declaration (.d.ts) file containing `declare module 'fs-extra';`
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(10,24): error TS2307: Cannot find module 'child_process' or its corresponding type declarations.
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(11,22): error TS7016: Could not find a declaration file for module 'inquirer'. '/home/runner/.yarn/berry/cache/inquirer-npm-7.1.0-b82227f199-7.zip/node_modules/inquirer/lib/inquirer.js' implicitly has an 'any' type.
  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR   Try `npm install @types/inquirer` if it exists or add a new declaration (.d.ts) file containing `declare module 'inquirer';`
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(12,18): error TS2307: Cannot find module 'path' or its corresponding type declarations.
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(13,19): error TS7016: Could not find a declaration file for module 'shelljs'. '/home/runner/.yarn/berry/cache/shelljs-npm-0.8.4-e2890f4ce2-7.zip/node_modules/shelljs/shell.js' implicitly has an 'any' type.
  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR   Try `npm install @types/shelljs` if it exists or add a new declaration (.d.ts) file containing `declare module 'shelljs';`
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(14,23): error TS7016: Could not find a declaration file for module 'lodash.kebabcase'. '/home/runner/.yarn/berry/cache/lodash.kebabcase-npm-4.1.1-89ffca7e1f-7.zip/node_modules/lodash.kebabcase/index.js' implicitly has an 'any' type.
  ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR   Try `npm install @types/lodash.kebabcase` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash.kebabcase';`
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(49,37): error TS2304: Cannot find name '__dirname'.
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(52,14): error TS7006: Parameter 'd' implicitly has an 'any' type.
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(171,15): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
  Error: ➤ YN0000: │ root-workspace-0b6124@workspace:. STDERR src/index.ts(173,23): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.

Strange, it looks like errors with types, but why didn't they show up before? Changes to this PR make nothing significant.

@lex111
Copy link
Contributor Author

lex111 commented Nov 12, 2020

I didn't realize right away that using npm in an E2E test for Yarn v2 was a really bad idea. Thus, I refactor release script, and now in order to initialize the project via npm, need to run the command yarn test:build:v2 -n (i.e. with the n option).

@slorber
Copy link
Collaborator

slorber commented Nov 13, 2020

What is this -n option?

@lex111
Copy link
Contributor Author

lex111 commented Nov 13, 2020

It's just short for npm, in any case, this option is needed as a last resort.

@slorber slorber merged commit 5f20200 into master Nov 16, 2020
@lex111 lex111 deleted the lex111/npm-flag-init-command branch November 17, 2020 15:01
@lex111 lex111 added this to the v2.0.0-alpha.67 milestone Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants