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

downmerge from parent #1

Merged
merged 35 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6e43c9b
chore(v2): Fix more eslint errors (#2976)
SamChou19815 Jun 21, 2020
fa99aeb
chore(v2): Remove extraneous package-lock.json (#2977)
SamChou19815 Jun 21, 2020
592dca9
chore(v2): Implement a simple E2E testing mechanism for `docusausus s…
SamChou19815 Jun 22, 2020
ee5e59f
fix(v2): fromExtensions and toExtensions translation with baseUrl (#2…
jknoxville Jun 22, 2020
2b4b6f7
feat(v2): replace yup validation by joi validation (#2962)
anshulrgoyal Jun 22, 2020
11b7ce5
feat(v2): Error when hooks depends on context is used outside of Layo…
SamChou19815 Jun 23, 2020
3c334d7
add warning for chunk overrides (related to https://github.com/facebo…
slorber Jun 23, 2020
ce10646
document that docs/blog-only modes should delete the existing homepage
slorber Jun 23, 2020
81d8553
feat(v2): option and config validation life cycle method for official…
anshulrgoyal Jun 24, 2020
20930dc
docs(v2): add plugin redirects production build note (#2983)
slorber Jun 24, 2020
5ccd24c
feat(v2): Support swizzling TypeScript components (#2671)
SamChou19815 Jun 25, 2020
65ce107
docs(v2): showcase Amphora Data (#2991)
xtellurian Jun 25, 2020
8304e82
docs(v2): Fix typo in markdown-features (#2973)
ehsanjso Jun 25, 2020
bdffd28
feat(v2): allow skipping build docs for next version (#2877)
lex111 Jun 25, 2020
d513dec
feat(v1): add deletedDocs config to escape from versioning fallback (…
aldeed Jun 25, 2020
f16258b
fix(v1): enableUpdateTime fails if local directory name has spaces (#…
amirulahmad Jun 25, 2020
71b5c27
chore(v2): Merge devDependencies in theme-classic (#2996)
SamChou19815 Jun 26, 2020
ec3c281
docs(v2): Document TypeScript support (#2997)
SamChou19815 Jun 26, 2020
3213955
chore(v2): use joi for config validation (#2987)
anshulrgoyal Jun 26, 2020
0f59cd1
feat(v2): add option validation for remaining official plugins (#2970)
teikjun Jun 26, 2020
b58a53e
fix(v2): Add two missing docusaurus core babel dependency (#3007)
SamChou19815 Jun 28, 2020
2e055f4
fix(v2): make client-redirect-plugin not baseUrl sensitive (#3010)
teikjun Jun 29, 2020
984e2d4
docs(v1): external links (#3011)
slorber Jun 30, 2020
cf97662
fix(v2): refactor routes.ts + add route hash for chunkNames key (#3001)
slorber Jun 30, 2020
c2bb03a
fix(v2): refactor color mode system (#3012)
slorber Jun 30, 2020
998e4d5
feat(v2): prompt user when default port is in use (#3006)
taylorallen0913 Jun 30, 2020
086d1b7
fix(v2): fix broken links on versions page (#3017)
teikjun Jul 1, 2020
cf5babd
chore(v2): Add E2E test for yarn v2 (#3008)
SamChou19815 Jul 1, 2020
9265de9
chore(v2): refactor scripts + add theme-classic watchmode (#2998)
slorber Jul 1, 2020
a5b2b60
feat(v2): add disableVersioning config to docs plugin (#2989)
slorber Jul 1, 2020
8aa6ef4
feat(v2): configureWebpack merge strategy + use file-loader for commo…
slorber Jul 1, 2020
46f794b
docs(v2): showcase Eta (#3022)
nebrelbug Jul 5, 2020
9b3da59
feat(v2): Plugin for Offline/PWA support (#2205)
codemonkey800 Jul 8, 2020
e5afd18
fix(v2): change description for blog post paginator (#3029)
teikjun Jul 8, 2020
a8b2e59
feat(v2): add useBaseUrlUtils() hook (#3033)
slorber Jul 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ packages/docusaurus-plugin-debug/lib/
packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js
packages/docusaurus-theme-classic/lib/

packages/docusaurus-1.x/.eslintrc.js
packages/docusaurus-init/templates/facebook/.eslintrc.js
14 changes: 4 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,23 @@ module.exports = {
],
'no-unused-vars': OFF,
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
'@typescript-eslint/ban-ts-comment': [
ERROR,
{'ts-expect-error': 'allow-with-description'},
],

// TODO re-enable some these as errors
// context: https://github.com/facebook/docusaurus/pull/2949
'@typescript-eslint/ban-ts-comment': WARNING,
'@typescript-eslint/ban-types': WARNING,
'import/prefer-default-export': WARNING,
'import/no-extraneous-dependencies': WARNING,
'no-useless-escape': WARNING,
'prefer-template': WARNING,
'no-shadow': WARNING,
'no-param-reassign': WARNING,
'no-else-return': WARNING,
'no-template-curly-in-string': WARNING,
'array-callback-return': WARNING,
camelcase: WARNING,
'no-nested-ternary': WARNING,
'object-shorthand': WARNING,
'no-restricted-syntax': WARNING,
'no-unused-expressions': WARNING,
'consistent-return': WARNING,
'no-useless-return': WARNING,
'@typescript-eslint/no-empty-function': WARNING,
'global-require': WARNING,
'prefer-destructuring': WARNING,
Expand All @@ -114,8 +110,6 @@ module.exports = {
'no-empty': WARNING,
'no-prototype-builtins': WARNING,
'no-case-declarations': WARNING,
'default-case': WARNING,
'dot-notation': WARNING,
},
overrides: [
{
Expand Down
43 changes: 41 additions & 2 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- master

jobs:
build:
yarn-v1:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -25,7 +25,46 @@ jobs:
- name: Installation
run: yarn
- name: Setup test-website project against master release
run: yarn test:build:v2
run: |
yarn test:build:v2
rm -rf node_modules
- name: Start test-website project
run: cd test-website && yarn start --no-open
env:
E2E_TEST: true
- name: Build test-website project
run: cd test-website && yarn build
env:
CI: true
yarn-v2:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Installation
run: yarn
- name: Setup test-website project against master release
run: |
KEEP_CONTAINER=true yarn test:build:v2
rm -rf node_modules
- name: Setup test-website project for Yarn v2
run: |
cd test-website
yarn set version berry
yarn config set pnpMode loose
yarn config set npmRegistryServer http://localhost:4873
yarn config set unsafeHttpWhitelist --json '["localhost"]'
yarn install
- name: Start test-website project
run: cd test-website && yarn start --no-open
env:
E2E_TEST: true
- name: Build test-website project
run: cd test-website && yarn build
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ packages/docusaurus-plugin-content-pages/lib/
packages/docusaurus-plugin-debug/lib/
packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-theme-classic/lib/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ packages/docusaurus-plugin-content-pages/lib/
packages/docusaurus-plugin-debug/lib/
packages/docusaurus-plugin-sitemap/lib/
packages/docusaurus-plugin-ideal-image/lib/
packages/docusaurus-theme-classic/lib/
__fixtures__
2 changes: 1 addition & 1 deletion admin/scripts/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ git diff --name-only -- '*.json' | sed 's, ,\\&,g' | xargs git checkout --
npm_config_registry="$CUSTOM_REGISTRY_URL" npx @docusaurus/init@"$NEW_VERSION" init test-website classic

# Stop Docker container
if ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
if (! $KEEP_CONTAINER) && ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
# Remove Docker container
docker container stop $CONTAINER_NAME > /dev/null
fi
Expand Down
24 changes: 22 additions & 2 deletions docs/api-site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ headerLinks: [
{ doc: "doc1", label: "Getting Started" },
// Link to page found at pages/en/help.js or if that does not exist, pages/help.js, for current language
{ page: "help", label: "Help" },
// Links to href destination
{ href: "https://github.com/", label: "GitHub" },
// Links to href destination, using target=_blank (external)
{ href: "https://github.com/", label: "GitHub", external: true },
// Links to blog generated by Docusaurus (${baseUrl}blog)
{ blog: true, label: "Blog" },
// Determines search bar position among links
Expand Down Expand Up @@ -128,6 +128,26 @@ customDocsPath: 'website-docs';

The default version for the site to be shown. If this is not set, the latest version will be shown.

#### `deletedDocs` [object]

Even if you delete the main file for a documentation page and delete it from your sidebar, the page will still be created for every version and for the current version due to [fallback functionality](versioning#fallback-functionality). This can lead to confusion if people find the documentation by searching and it appears to be something relevant to a particular version but actually is not.

To force removal of content beginning with a certain version (including for current/next), add a `deletedDocs` object to your config, where each key is a version and the value is an array of document IDs that should not be generated for that version and all later versions.

Example:

```js
{
deletedDocs: {
"2.0.0": [
"tagging"
]
}
}
```

The version keys must match those in `versions.json`. Assuming the versions list in `versions.json` is `["3.0.0", "2.0.0", "1.1.0", "1.0.0"]`, the `docs/1.0.0/tagging` and `docs/1.1.0/tagging` URLs will work but `docs/2.0.0/tagging`, `docs/3.0.0/tagging`, and `docs/tagging` will not. The files and folders for those versions will not be generated during the build.

#### `docsUrl` [string]

The base URL for all docs file. Set this field to `''` to remove the `docs` prefix of the documentation URL. If unset, it is defaulted to `docs`.
Expand Down
2 changes: 2 additions & 0 deletions docs/guides-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Only files in the `docs` directory and sidebar files that differ from those of t

For example, a document with the original id `doc1` exists for the latest version, `1.0.0`, and has the same content as the document with the id `doc1` in the `docs` directory. When a new version `2.0.0` is created, the file for `doc1` will not be copied into `versioned_docs/version-2.0.0/`. There will still be a page for `docs/2.0.0/doc1.html`, but it will use the file from version `1.0.0`.

Because of the way this fallback works, pages that you delete are not really deleted from the website unless you tell Docusaurus to skip fallback after a certain version. To do this, use the [`deletedDocs`](api-site-config.md#deleteddocs-object) option in `siteConfig.js`.

## Renaming Existing Versions

To rename an existing version number to something else, first make sure the following script is in your `package.json` file:
Expand Down
27 changes: 18 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
"packages/docusaurus-init/templates/*"
],
"scripts": {
"start": "yarn tsc && yarn start:v2",
"start": "yarn build:packages && yarn start:v2",
"start:v1": "yarn workspace docusaurus-1-website start",
"start:v2": "yarn workspace docusaurus-2-website start",
"start:v2:watch": "nodemon --watch \"./packages/*/lib/**/*.*\" --exec \"yarn start:v2\"",
"build": "yarn tsc && yarn build:v2",
"build": "yarn build:packages && yarn build:v2",
"build:packages": "lerna run build --no-private",
"build:v1": "yarn workspace docusaurus-1-website build",
"build:v2": "yarn workspace docusaurus-2-website build",
"serve": "yarn serve:v2",
"serve:v1": "serve website-1.x/build/docusaurus",
"serve:v2": "serve website/build",
"serve:v2:ssl": "yarn serve:v2:ssl:gencert && yarn serve:v2:ssl:message && yarn serve:v2:ssl:serve",
"serve:v2:ssl:gencert": "openssl req -x509 -nodes -days 365 -newkey rsa:4096 -subj \"/C=US/ST=Docusaurus/L=Anywhere/O=Dis/CN=localhost\" -keyout ./website/.docusaurus/selfsigned.key -out ./website/.docusaurus/selfsigned.crt",
"serve:v2:ssl:message": "echo '\n\n\nServing Docusaurus with HTTPS on localhost requires to disable the Chrome security: chrome://flags/#allow-insecure-localhost\n\n\n'",
"serve:v2:ssl:serve": "serve website/build --ssl-cert ./website/.docusaurus/selfsigned.crt --ssl-key ./website/.docusaurus/selfsigned.key",
"changelog": "lerna-changelog",
"postinstall": "yarn tsc",
"postinstall": "yarn build:packages",
"prettier": "prettier --config .prettierrc --write \"**/*.{js,ts}\"",
"prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,ts}\"",
"prettier-docs": "prettier --config .prettierrc --write \"**/*.md\"",
Expand All @@ -28,17 +32,16 @@
"lerna": "lerna",
"test": "jest",
"test:build:v2": "./admin/scripts/test-release.sh",
"tsc": "lerna run tsc --no-private",
"tsc": "yarn build:packages && echo '\n\nDOCUSAURUS: yarn tsc is deprecated and will be removed, use yarn build:packages instead\n\n'",
"watch": "yarn lerna run --parallel --no-private watch",
"clear": "yarn rimraf website/.docusaurus && rimraf -rf website/node_modules/.cache && yarn lerna exec 'yarn rimraf lib' --ignore docusaurus"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/cli": "^7.9.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^3.3.0",
"@typescript-eslint/parser": "^3.3.0",
"@types/express": "^4.17.2",
"@types/fs-extra": "^8.0.1",
"@types/inquirer": "^6.5.0",
Expand All @@ -54,13 +57,19 @@
"@types/lodash.pick": "^4.4.6",
"@types/lodash.pickby": "^4.6.6",
"@types/node": "^13.11.0",
"@types/react": "^16.9.13",
"@types/prismjs": "^1.16.1",
"@types/react": "^16.9.38",
"@types/react-dev-utils": "^9.0.1",
"@types/react-helmet": "^6.0.0",
"@types/react-loadable": "^5.5.3",
"@types/react-router-config": "^5.0.1",
"@types/semver": "^7.1.0",
"@types/shelljs": "^0.8.6",
"@types/webpack": "^4.41.0",
"@types/webpack-dev-server": "^3.9.0",
"@types/webpack-merge": "^4.1.5",
"@typescript-eslint/eslint-plugin": "^3.3.0",
"@typescript-eslint/parser": "^3.3.0",
"babel-eslint": "^10.0.3",
"concurrently": "^5.2.0",
"enzyme": "^3.10.0",
Expand All @@ -85,7 +94,7 @@
"rimraf": "^3.0.2",
"serve": "^11.3.2",
"stylelint": "^13.2.1",
"typescript": "^3.7.2"
"typescript": "^3.9.5"
},
"peerDependencies": {
"stylelint-copyright": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-1.x/lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getGitLastUpdated(filepath) {
const silentState = shell.config.silent; // Save old silent state.
shell.config.silent = true;
const result = shell
.exec(`git log --follow --summary --format="%ct, %an" ${filepath}`)
.exec(`git log --follow --summary --format="%ct, %an" "${filepath}"`)
.stdout.trim();
shell.config.silent = silentState;

Expand Down
21 changes: 21 additions & 0 deletions packages/docusaurus-1.x/lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const utils = require('./utils.js');

const docsPart = `${siteConfig.docsUrl ? `${siteConfig.docsUrl}/` : ''}`;

// Get a list of all IDs that have been deleted in any version.
// We will assume these should not be in the current/next version.
const allDeletedIds = new Set();
if (siteConfig.deletedDocs) {
Object.values(siteConfig.deletedDocs).forEach((idList) => {
idList.forEach((id) => allDeletedIds.add(id));
});
}

const SupportedHeaderFields = new Set([
'id',
'title',
Expand Down Expand Up @@ -238,6 +247,12 @@ function generateMetadataDocs() {
return;
}
const metadata = res.metadata;
if (
allDeletedIds.has(metadata.id) ||
(metadata.original_id && allDeletedIds.has(metadata.original_id))
) {
return;
}
metadatas[metadata.id] = metadata;

// create a default list of documents for each enabled language based on docs in English
Expand Down Expand Up @@ -290,6 +305,12 @@ function generateMetadataDocs() {
return;
}
const metadata = res.metadata;
if (
allDeletedIds.has(metadata.id) ||
(metadata.original_id && allDeletedIds.has(metadata.original_id))
) {
return;
}
metadatas[metadata.id] = metadata;
}
});
Expand Down
37 changes: 34 additions & 3 deletions packages/docusaurus-1.x/lib/server/versionFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,46 @@ function docVersion(id, reqVersion) {
// iterate through versions until a version less than or equal to the requested
// is found, then check if that version has an available file to use
let requestedFound = false;
let availableVersion = null;
let deletedDocs = null;
if (siteConfig.deletedDocs) {
// Config file may have either Array or Set for each version. Convert
// all to Set to make the check faster in the versions loop below.
deletedDocs = {};
Object.keys(siteConfig.deletedDocs).forEach((deletedDocVersion) => {
deletedDocs[deletedDocVersion] = new Set(
siteConfig.deletedDocs[deletedDocVersion],
);
});
}
for (let i = 0; i < versions.length; i++) {
if (versions[i] === reqVersion) {
requestedFound = true;
}
if (requestedFound && available[id].has(versions[i])) {
return versions[i];
if (requestedFound) {
// If this ID is deleted as of any version equal to or prior to
// the requested, return null.
if (
deletedDocs &&
deletedDocs[versions[i]] &&
deletedDocs[versions[i]].has(id)
) {
return null;
}
if (!availableVersion && available[id].has(versions[i])) {
availableVersion = versions[i];
// Note the fallback version but keep looping in case this ID
// was deleted as of a previous version.
//
// If `deletedDocs` config isn't used, we can return immediately
// and avoid unnecessary looping.
if (!deletedDocs) {
break;
}
}
}
}
return null;
return availableVersion;
}

// returns whether a given file has content that differ from the
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const chalk = require('chalk');
const semver = require('semver');
const path = require('path');
const program = require('commander');
const {init} = require('../lib');
const {default: init} = require('../lib');
const requiredVersion = require('../package.json').engines.node;

if (!semver.satisfies(process.version, requiredVersion)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://github.com/facebook/docusaurus/issues"
},
"scripts": {
"tsc": "tsc",
"build": "tsc",
"watch": "tsc --watch"
},
"bin": {
Expand Down
7 changes: 5 additions & 2 deletions packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ function isValidGitRepoUrl(gitRepoUrl: string): boolean {
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
}

async function updatePkg(pkgPath: string, obj: any): Promise<void> {
async function updatePkg(
pkgPath: string,
obj: Record<string, unknown>,
): Promise<void> {
const content = await fs.readFile(pkgPath, 'utf-8');
const pkg = JSON.parse(content);
const newPkg = Object.assign(pkg, obj);

await fs.outputFile(pkgPath, JSON.stringify(newPkg, null, 2));
}

export async function init(
export default async function init(
rootDir: string,
siteName?: string,
reqTemplate?: string,
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-init/templates/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@docusaurus/core": "^2.0.0-alpha.58",
"@docusaurus/preset-bootstrap": "^2.0.0-alpha.58",
"@mdx-js/react": "^1.5.8",
"classnames": "^2.2.6",
"react": "^16.8.4",
"react-dom": "^16.8.4"
Expand Down
Loading