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

Use Path module functions and properties in server and generate #490

Merged
merged 6 commits into from
Mar 12, 2018

Conversation

JoelMarcey
Copy link
Contributor

Fixes #468

Motivation

We want to be more robust in our path string handling in order to not fail on various platforms.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Local Docusaurus site testing

Related PRs

N/A

@JoelMarcey
Copy link
Contributor Author

cc @Happy-Ferret

@JoelMarcey JoelMarcey mentioned this pull request Mar 8, 2018
@Happy-Ferret
Copy link
Contributor

> docusaurus-build

generate.js triggered...
feed.js triggered...
feed.js triggered...
sitemap.js triggered...
fs.js:641
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EISDIR: illegal operation on a directory, open 'C:\Users\user\Desktop
\Gitlab\forks\docusaurus-example\website\build\test-site'
    at Error (native)
    at Object.fs.openSync (fs.js:641:18)
    at Object.fs.writeFileSync (fs.js:1347:33)
    at C:/Users/user/Desktop/Gitlab/forks/docusaurus-example/website/node_mo
dules/docusaurus/lib/server/generate.js:359:10
    at Array.forEach (native)
    at execute (C:/Users/user/Desktop/Gitlab/forks/docusaurus-example/websit
e/node_modules/docusaurus/lib/server/generate.js:316:9)
    at Object.<anonymous> (C:\Users\user\Desktop\Gitlab\forks\docusaurus-exa
mple\website\node_modules\docusaurus\lib\build-files.js:35:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! @ build: `docusaurus-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ build script 'docusaurus-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     docusaurus-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\user\Desktop\Gitlab\forks\docusaurus-example\website\n
pm-debug.log

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle @~prebuild: @
6 silly lifecycle @~prebuild: no script for prebuild, continuing
7 info lifecycle @~build: @
8 verbose lifecycle @~build: unsafe-perm in lifecycle true
9 verbose lifecycle @~build: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\user\Desktop\Gitlab\forks\docusaurus-example\website\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jre1.8.0_73\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Go\bin;C:\Program Files\Git\cmd;C:\Program Files\Emscripten\node\0.12.2_64bit;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\LLVM\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\IBM\Bluemix\bin;C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts\;C:\Users\user\AppData\Local\Programs\Python\Python35\;C:\Users\user\.cargo\bin;C:\msys64\mingw64\bin;D:\alias;C:\mozilla-build\python;C:\mozilla-build\mozmake;C:\Users\user\AppData\Local\Android\android-sdk\platform-tools;"C:\Program Files\Emscripten\clang\fastcomp\build_incoming_vs2013_64\RelWithDebInfo\bin";C:\Program Files\Emscripten\node\4.1.1_64bit\bin;C:\Program Files\Emscripten\emscripten\incoming;C:\Program Files (x86)\Microsoft VS Code;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\user\Desktop\Gitlab\Go\bin;C:\Program Files\MongoDB\Server\3.4\bin;C:\Program Files\Java\jdk1.8.0_111\bin;C:\Users\user\AppData\Roaming\npm;C:\Gradle\gradle-3.5\bin
10 verbose lifecycle @~build: CWD: C:\Users\user\Desktop\Gitlab\forks\docusaurus-example\website
11 silly lifecycle @~build: Args: [ '/d /s /c', 'docusaurus-build' ]
12 silly lifecycle @~build: Returned: code: 1  signal: null
13 info lifecycle @~build: Failed to exec build script
14 verbose stack Error: @ build: `docusaurus-build`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:886:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid @
16 verbose cwd C:\Users\user\Desktop\Gitlab\forks\docusaurus-example\website
17 error Windows_NT 6.3.9600
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
19 error node v6.10.3
20 error npm  v3.10.10
21 error code ELIFECYCLE
22 error @ build: `docusaurus-build`
22 error Exit status 1
23 error Failed at the @ build script 'docusaurus-build'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the  package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     docusaurus-build
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret is that error different than what you were getting before?

Sent with GitHawk

@Happy-Ferret
Copy link
Contributor

@JoelMarcey

I wasn't getting any errors prior to that (it just wouldn't copy the .html files to the root folder).
I highly suspect it's one of these weird Windows idiosyncrasies at play here. Probably trying to add or remove files while they're being accessed by another process.

Will see if I can debug it later.

@JoelMarcey
Copy link
Contributor Author

Well, I think this may be progress at least. It is trying to do something in the right directory, this time. The question is why is it throwing an error.

I guess it is time for me to spin up a Windows VM 😄

@Happy-Ferret
Copy link
Contributor

Lol. If you do, let me be the first to welcome you to Microsoft Windows development hell.
The food is awful, there's no beer and you better get a tetanus shot.

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret Using my Windows VM - which has been, um, fun 😄 - I think I fixed the issue. If you would like to double check me by testing, I would appreciate it.

The build should now produce files in both the root and en dir.

@Happy-Ferret
Copy link
Contributor

Installed your changes via npm install https://github.com/JoelMarcey/Docusaurus#use-path-functions
and then ran npm run build from website/.

Output:

> docusaurus-build

generate.js triggered...
feed.js triggered...
feed.js triggered...
sitemap.js triggered...
C:\Users\user\Desktop\git\test-doc\website\node_modules\docusaurus\lib\server\generate.js:371
      var langParts = match[1].split('/');
                           ^

TypeError: Cannot read property '1' of null
    at C:/Users/user/Desktop/git/test-doc/website/node_modules/docusaurus/lib/server/generate.js:441:25
    at Array.forEach (native)
    at execute (C:/Users/user/Desktop/git/test-doc/website/node_modules/docusaurus/lib/server/generate.js:416:9)
    at Object.<anonymous> (C:\Users\user\Desktop\git\test-doc\website\node_modules\docusaurus\lib\build-files.js:35:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build: `docusaurus-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above

Am I doing something wrong?

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret No. I forgot something 😄

I normalized some files after globs and forgot to change a / to path.sep. f89fdc4

Can you try now?

@Happy-Ferret
Copy link
Contributor

Same error still and it fails at the 1, saying it's null. Doesn't even get to the sep part.

@JoelMarcey
Copy link
Contributor Author

Ah right - it is because of this:

const regexLang = /\/pages\/(.*)\//;

it is using the / separator. It needs to handle both.

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret Ok. 04e836f

🤞

@Happy-Ferret
Copy link
Contributor

  C:\Users\user\Desktop\Gitlab\forks\SMC-Docs\website\node_modules\docusaurus\lib\server\generate.js:369
      var regexLang = new RegExp(sep + 'pages' + sep + '(.*)' + sep);
                      ^

SyntaxError: Invalid regular expression: /\pages\(.*)\/: Unmatched ')'
    at RegExp (native)
    at C:/Users/user/Desktop/Gitlab/forks/SMC-Docs/website/node_modules/docusaurus/lib/server/generate.js:439:25
    at Array.forEach (native)
    at execute (C:/Users/user/Desktop/Gitlab/forks/SMC-Docs/website/node_modules/docusaurus/lib/server/generate.js:416:9)
    at Object.<anonymous> (C:\Users\user\Desktop\Gitlab\forks\SMC-Docs\website\node_modules\docusaurus\lib\build-files.js:35:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Out of curiosity: What kind of Windows VM are you testing your code on? Windows 10 with WSL (bash) or CMD? The latter should be the target, as WSL ran fine with just the regular POSIX compliant code anyways.

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret it has been a while since I have used Windows - so I bet I have been using the wrong cli then. Tomorrow, I will use ‘cmd.exe’ and see what happens. I think we are close though.

Just to verify, can you run the local web server successfully still via ‘npm start’ ??

Sent with GitHawk

@Happy-Ferret
Copy link
Contributor

Happy-Ferret commented Mar 12, 2018

Yep. npm start still exhibits the correct behavior.

@JoelMarcey
Copy link
Contributor Author

@Happy-Ferret Ok. I got it to build with cmd.exe. Had to escape the regular expression. a56d669

screenshot 2018-03-12 08 59 41

@JoelMarcey
Copy link
Contributor Author

I am going to merge this. If I missed something, I can push more fixes separately. However, I think this solves a lot of the Windows issues that were happening.

@JoelMarcey JoelMarcey merged commit cbdab2b into facebook:master Mar 12, 2018
endiliey added a commit to endiliey/Docusaurus that referenced this pull request May 19, 2018
`'en'` is written as `en`
endiliey added a commit to endiliey/Docusaurus that referenced this pull request May 19, 2018
`'en'` is written as `en`
JoelMarcey pushed a commit that referenced this pull request May 19, 2018
`'en'` is written as `en`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants