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

WIP, updating server.js to use JSDOM to fix isExternal, but also some… #3

Conversation

trusktr
Copy link

@trusktr trusktr commented May 22, 2020

This is a "draft" pull request, for discussion. Let's figure out what we want to do.

// transforms: {
// generator: false,
// },
// }),
Copy link
Author

Choose a reason for hiding this comment

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

The output is nice without this. async functions and generators work great in newer Node.


console.log(dest)
console.log(dest);
Copy link
Author

Choose a reason for hiding this comment

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

auto formatting based on the repo's eslint/prettier config files.

@@ -48,7 +48,7 @@
"pub": "sh build/release.sh",
"postinstall": "opencollective-postinstall"
},
"husky": {
"husky-OFF": {
Copy link
Author

Choose a reason for hiding this comment

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

temporary. if we accept any changes, they should all be formatted.

Actually we should just go ahead and format the whole code base all in one PR and get it out of the way if we're going to have the eslint/prettier configs in the repo.


function cwd(...args) {
return resolve(process.cwd(), ...args);
}

// Borrowed from https://j11y.io/snippets/getting-a-fully-qualified-url.
function qualifyURL(url) {
// TODO this doesn't work in Node, passing in / results in /. It doesn't know the origin. Maybe we should update `location` globally first.
Copy link
Author

Choose a reason for hiding this comment

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

nevermind this comment. I fixed it by configuring JSDom.

this.html = template;
this.config = config = Object.assign({}, config, {
routerMode: 'history',
});
this.cache = cache;

// this.cache = cache; // not used for anything?
Copy link
Author

Choose a reason for hiding this comment

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

Doesn't seem to be used for anything.

<!--inject-config-->
<script src="/lib/docsify.js"></script>
</body>
</html>`,
Copy link
Author

@trusktr trusktr May 22, 2020

Choose a reason for hiding this comment

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

moved to a separate HTML file so it can be re-used (f.e. here, and in the test code).

},
path: './'
})
// path: './', // not used for anything?
Copy link
Author

@trusktr trusktr May 22, 2020

Choose a reason for hiding this comment

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

Unused? The Renderer constructor doesn't use this option for anything, unless I missed it.

Copy link
Author

@trusktr trusktr May 22, 2020

Choose a reason for hiding this comment

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

Actually, I found out because I add // @ts-check at the top of any JS file and have TypeScript do live type checking in VS Code, and it complained that the option was unused (which appears to be the case).

Looks like we have some cleanup to do.

// path: './', // not used for anything?
});

expect(renderer).to.be.an.instanceof(Renderer);
Copy link
Author

Choose a reason for hiding this comment

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

A starting point to officially test the server code.

server.js Outdated
const { initJSDOM } = require('./test/_helper');

const dom = initJSDOM();
dom.reconfigure({ url: 'https://127.0.0.1:3000' });
Copy link
Author

@trusktr trusktr May 22, 2020

Choose a reason for hiding this comment

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

This is the most important change. This makes isExternal work.

Renderer already needs to use DOM APIs anyways, so it's not a big deal to set up JSDom here. I'm not sure how the DOM APIs were being set up before though... Unless this server.js never worked? What is it used for?

const {
Renderer,
getDefaultTemplate,
} = require('./packages/docsify-server-renderer/index');
Copy link
Author

@trusktr trusktr May 22, 2020

Choose a reason for hiding this comment

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

Import the ES Modules. Much nicer experience in the debugger (Chrome devtools).

Try it:

npm i -g ndb
SSR=true ndb server.js

Once you run it, you should see an error inside the compiler.path() method. Pause devtools on uncaught exceptions in the Sources tab.

getDefaultTemplate,
} = require('./packages/docsify-server-renderer/index');

debugger;
Copy link
Author

Choose a reason for hiding this comment

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

temporary. I will delete this commit and recreate the branch all cleaned up. We just need to decide what to do.

@anikethsaha
Copy link
Owner

I didnt give a deep look but it looks great.

I will check this locally.

we can support node v10 as a minimum.

also, for this docsifyjs#1128, I was thinking we can create a separate PR with your implement just to reduce the complexity? It will help you as well to work in that better.

we can open the PR just for the reference.

what do you think?

@trusktr
Copy link
Author

trusktr commented May 23, 2020

Sure. 👍

Probably we should open any new branches in the main repo, that way if we do pull requests onto each others' branches we can view them all in the main repo and other people can chime in too (instead of opening PRs in my or your personal repos).

@anikethsaha
Copy link
Owner

great 👍

@anikethsaha anikethsaha force-pushed the fix-validating-remote-content branch from 45023a4 to 1e3dd13 Compare June 14, 2020 07:12
…rk. Need to make a test to test that DOMPurify is working, and also isExternal is working using <img> API
@trusktr
Copy link
Author

trusktr commented Jun 17, 2020

Moving this to a PR in the main repo for visibility; docsifyjs#1227

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.

2 participants