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

Feature/issue 855 prerender default to false optional puppeteer #860

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Jan 12, 2022

Related Issue

part of #855 / #857 and now tracked by #916

Not sure if this is the best way, so please feel free to make suggestions

Diff between this and 857 for easier review

Summary of Changes

  1. "Hoisted" compilation so command scripts could be run lazily (this avoided calling lib/browser.js pre-maturely before we could get the prerender config value
  2. Added an import check and fallback installation handling

Almost have this working, but can't get it to work for the first time, only the second time... 😕

## delete puppeteer and run test - installs!, but tests fails :( 
% rm -rf node_modules/puppeteer && yarn test
yarn run v1.22.5
$ cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict c8 mocha


  Build Greenwood With:
    Prerender Configuration turned on
-------------------------------------------------------

Welcome to Greenwood (v0.21.1) ♻️
-------------------------------------------------------

Initializing project config

Initializing project workspace contexts

Generating graph of workspace files...

building from local sources...

Running Greenwood with the build command.

puppeteer not detected Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'puppeteer' imported from /Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/index.js
    at packageResolve (internal/modules/esm/resolve.js:655:9)
    at moduleResolve (internal/modules/esm/resolve.js:696:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:88:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
    at Loader.import (internal/modules/esm/loader.js:176:28)
    at importModuleDynamically (internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at run (file:///Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/index.js:72:9) {
  code: 'ERR_MODULE_NOT_FOUND'
}
auto intalling puppeteer...

auto installation successful!

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/node_modules/puppeteer/' imported from /Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/browser.js
    at legacyMainResolve (internal/modules/esm/resolve.js:225:9)
    at packageResolve (internal/modules/esm/resolve.js:648:14)
    at moduleResolve (internal/modules/esm/resolve.js:696:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:88:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
    at link (internal/modules/esm/module_job.js:55:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

      1) "before all" hook in "Prerender Configuration turned on"


  0 passing (14s)
  1 failing

  1) Build Greenwood With:
       Prerender Configuration turned on
         "before all" hook in "Prerender Configuration turned on":
     Error: the string "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '/Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/node_modules/puppeteer/' imported from /Users/owenbuckley/Workspace/project-evergreen/repos/greenwood/packages/cli/src/lib/browser.js\n    at legacyMainResolve (internal/modules/esm/resolve.js:225:9)\n    at packageResolve (internal/modules/esm/resolve.js:648:14)\n    at moduleResolve (internal/modules/esm/resolve.js:696:18)\n    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)\n    at Loader.resolve (internal/modules/esm/loader.js:88:40)\n    at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)\n    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)\n    at link (internal/modules/esm/module_job.js:55:36) {\n  code: 'ERR_MODULE_NOT_FOUND'\n}\n" was thrown, throw an Error :)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)


## verify it is there in _package.json_ though
% git diff packages/cli/package.json
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 9716e21c..141223ba 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -23,6 +23,9 @@
   "publishConfig": {
     "access": "public"
   },
+  "peerDependencies": {
+    "puppeteer": "^10.2.0"
+  },
   "dependencies": {
     "@rollup/plugin-node-resolve": "^13.0.0",
     "@rollup/plugin-replace": "^2.3.4",


## Run test again (success!)
owenbuckley@Owens-MBP-2 greenwood % yarn test
yarn run v1.22.5
$ cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict c8 mocha


  Build Greenwood With:
    Prerender Configuration turned on
-------------------------------------------------------

Welcome to Greenwood (v0.21.1) ♻️
-------------------------------------------------------

Initializing project config

Initializing project workspace contexts

Generating graph of workspace files...

building from local sources...

Running Greenwood with the build command.

Started local development server at localhost:1984

Prerendering pages at http://127.0.0.1:1984

pages to render
 /
 /404/

prerendering page... /

prerendering page... /404/

prerendering complete for page /.

prerendering complete for page /404/.

done prerendering all pages

copying file... .greenwood/graph.json

      Running Smoke Tests: Prerender Configuration turned on
        Public Directory Generated Output
          ✔ should create a public directory
          ✔ should output a single index.html file (home page)
          ✔ should output one graph.json file
          ✔ should not output any map files for HTML pages
      Running Smoke Tests: Prerender Configuration turned on
        Index (Home) page
          ✔ should do all the common checks for an HTML page
      Default output for index.html
        ✔ should have the expected heading text within the index page in the public directory
        ✔ should have prerendered content from <app-header> component
        head section tags
          ✔ should have a <title> tag in the <head>
          ✔ should have five default <meta> tags in the <head>
          ✔ should have default mobile-web-app-capable <meta> tag
          ✔ should have default apple-mobile-web-app-capable <meta> tag
          ✔ should have default apple-mobile-web-app-status-bar-style <meta> tag

  Running Common Index Smoke Tests for Prerender Configuration turned on
    document <html>
      ✔ should have an <html> tag with the DOCTYPE attribute
      ✔ should have a <head> tag with the lang attribute on it
      ✔ should have matching opening and closing <html> tags
    document <head>
      ✔ should have matching opening and closing <head> tags in the <head>
      ✔ should have a <title> tag in the <head>
      ✔ should have matching opening and closing <script> tags in the <head>
      ✔ should have matching opening and closing <link> tags in the <head>
      ✔ should have matching opening and closing <style> tags in the <head>
      ✔ should have default viewport <meta> tag
      ✔ should have default charset <meta> tag
    document <body>
      ✔ should have matching opening and closing <body> tags
      ✔ should have no <script> tags in the <body>
      ✔ should have no <link> tags in the <body>
      ✔ should have no <style> tags in the <body>
      ✔ should have no <meta> tags in the <body>
      ✔ should have no <content-outlet> tags in the <body>
      ✔ should have no <page-outlet> tags in the <body>
      ✔ should not have any sourcemap inlining for Rollup HTML entry points


  30 passing (6s)

TODO

  1. fix the optional install issue ☝️
  2. get correct puppeteer version from package.json
  3. detect package manager

@thescientist13 thescientist13 added CLI discussion tied to an ongoing discussion or meeting notes feature New feature or request labels Jan 12, 2022
@thescientist13 thescientist13 mentioned this pull request Mar 13, 2022
21 tasks
@thescientist13 thescientist13 added documentation Greenwood specific docs SSR labels Mar 18, 2022
@thescientist13 thescientist13 changed the base branch from master to release/0.25.0 March 18, 2022 23:40
@thescientist13 thescientist13 changed the base branch from release/0.25.0 to master March 18, 2022 23:40
@thescientist13
Copy link
Member Author

I wonder if it is working, but the exception is blowing up NodeJS? Might need to look for another detection method...

@thescientist13
Copy link
Member Author

closing in favor of #917

@thescientist13 thescientist13 deleted the feature/issue-855-prerender-default-to-false-optional-puppeteer branch July 20, 2022 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI discussion tied to an ongoing discussion or meeting notes documentation Greenwood specific docs feature New feature or request SSR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant