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

misc: ignore some files during npm publish #6092

Merged
merged 13 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/create-docusaurus/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
copyUntypedFiles.js
.tsbuildinfo
__tests__

# Files in the templates need to stay
/tsconfig*
/src
1 change: 1 addition & 0 deletions packages/docusaurus-cssnano-preset/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-mdx-loader/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-mdx-loader/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-migrate/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__

src
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-client-redirects/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-content-blog/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-content-docs/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-content-pages/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-debug/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-google-analytics/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-google-gtag/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
3 changes: 3 additions & 0 deletions packages/docusaurus-plugin-ideal-image/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-pwa/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-plugin-sitemap/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/createSitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/

import {SitemapStream, streamToPromise} from 'sitemap';
import {PluginOptions} from './types';
import type {Options} from '@docusaurus/plugin-sitemap';
import {DocusaurusConfig} from '@docusaurus/types';
import {addTrailingSlash} from '@docusaurus/utils';
import {applyTrailingSlash} from '@docusaurus/utils-common';

export default async function createSitemap(
siteConfig: DocusaurusConfig,
routesPaths: string[],
options: PluginOptions,
options: Options,
): Promise<string> {
const {url: hostname} = siteConfig;
if (!hostname) {
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import fs from 'fs-extra';
import path from 'path';
import {PluginOptions} from './types';
import type {Options} from '@docusaurus/plugin-sitemap';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the same type on purpose 🤪 (also a good reason why one PR = one change is a good idea)

  • Options is the partial type that the users are using in configuration, documented with JSDoc annotations (somehow it's TS public API surface)
  • PluginOptions is the complete normalized type with defaults applied

Users should use Options in config

Internally, we should use PluginOptions because we know that normalization was already applied in docusaurus core and it's the actual type that gets injected in the plugin

I know that the naming convention is not very explicit, not sure how to find better names.

Options looks to be better for public API surface as it's simpler to use convention in JSDoc annotations without reading any doc.

Does it make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes I already made have taken that into account. These options are never normalized and are fully partial throughout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see

Still it might be useful to keep a convention of having 2 distinct types in each plugin so that they all look the same, even if the 2 types are the same in this case. If one day we refactor and add some option with a default value to this plugin, we'll have to revert this change, while we could just update the normalized type otherwise. Type aliases are also useful to convey meaning type PluginOptions = Options 🤪

Copy link
Collaborator

Choose a reason for hiding this comment

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

And in this case it's not 100% true either. These options are normalized, all values have defaults, and the type that the plugin constructor should receive is not partial, but a complete type with all values being set:

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well—that means the types we had previously were problematic 🙈 If you look at the deleted types file, the values are still optional.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yes that might totally be the case 😄 PluginOptions should have non-optional types

import createSitemap from './createSitemap';
import {
LoadContext,
Expand All @@ -20,7 +20,7 @@ import {PluginOptionSchema} from './pluginOptionSchema';

export default function pluginSitemap(
_context: LoadContext,
options: PluginOptions,
options: Options,
): Plugin<void> {
return {
name: 'docusaurus-plugin-sitemap',
Expand All @@ -47,7 +47,7 @@ export default function pluginSitemap(
export function validateOptions({
validate,
options,
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
}: OptionValidationContext<Options>): ValidationResult<Options> {
const validatedOptions = validate(PluginOptionSchema, options);
return validatedOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

export type Options = Partial<import('./types').PluginOptions>;
import {EnumChangefreq} from 'sitemap';

export type Options = {
changefreq?: EnumChangefreq;
priority?: number;
trailingSlash?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import {Joi} from '@docusaurus/utils-validation';
import {EnumChangefreq} from 'sitemap';
import {PluginOptions} from './types';
import type {Options} from '@docusaurus/plugin-sitemap';

export const DEFAULT_OPTIONS: Required<PluginOptions> = {
export const DEFAULT_OPTIONS: Required<Options> = {
changefreq: EnumChangefreq.WEEKLY,
priority: 0.5,
trailingSlash: false,
Expand Down
14 changes: 0 additions & 14 deletions packages/docusaurus-plugin-sitemap/src/types.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/docusaurus-preset-classic/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-remark-plugin-npm2yarn/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-remark-plugin-npm2yarn/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-theme-classic/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__

lib/theme
lib-next/**
!lib-next/theme/**

babel.config.js
7 changes: 2 additions & 5 deletions packages/docusaurus-theme-classic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {createRequire} from 'module';
import type {Plugin as PostCssPlugin} from 'postcss';
import rtlcss from 'rtlcss';
import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
import type {Options} from '@docusaurus/theme-classic';

const requireFromDocusaurusCore = createRequire(
require.resolve('@docusaurus/core/package.json'),
Expand Down Expand Up @@ -89,13 +90,9 @@ function getInfimaCSSFile(direction: string) {
}.css`;
}

export type PluginOptions = {
customCss?: string | string[];
};

export default function docusaurusThemeClassic(
context: DocusaurusContext, // TODO: LoadContext is missing some of properties
options: PluginOptions,
options: Options,
): Plugin<void> {
const {
siteConfig: {themeConfig: roughlyTypedThemeConfig},
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

declare module '@docusaurus/theme-classic' {
export type Options = Partial<import('./index').PluginOptions>;
export type Options = {
customCss?: string | string[];
};
}

declare module '@theme/AnnouncementBar' {
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-theme-common/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-theme-common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "esnext",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-theme-live-codeblock/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
4 changes: 4 additions & 0 deletions packages/docusaurus-theme-search-algolia/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
6 changes: 6 additions & 0 deletions packages/docusaurus-theme-translations/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__

update*
4 changes: 0 additions & 4 deletions packages/docusaurus-theme-translations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"description": "Docusaurus theme translations.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"locales",
"lib"
],
"publishConfig": {
"access": "public"
},
Expand Down
6 changes: 1 addition & 5 deletions packages/docusaurus-theme-translations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import path from 'path';
import fs from 'fs-extra';

function getDefaultLocalesDirPath(): string {
const parentDirPath = path.join(__dirname, '..');
const pkg = JSON.parse(
fs.readFileSync(path.join(parentDirPath, 'package.json'), 'utf8'),
);
return path.join(parentDirPath, pkg.files[0]);
return path.join(__dirname, '../locales');
}

// Return an ordered list of locales we should try
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-theme-translations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus-theme-translations/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ const {extractThemeCodeMessages} = require('./update');
const path = require('path');
const fs = require('fs-extra');
const {mapValues, pickBy} = require('lodash');
const pkg = require('./package.json');

// Seems the 5s default timeout fails sometimes
jest.setTimeout(15000);

describe('theme-translations package', () => {
test(`to have base messages files contain EXACTLY all the translations extracted from the theme. Please run "yarn workspace @docusaurus/theme-translations update" to keep base messages files up-to-date.`, async () => {
const baseMessagesDirPath = path.join(__dirname, pkg.files[0], 'base');
const baseMessagesDirPath = path.join(__dirname, 'locales/base');
const baseMessages = pickBy(
await fs
.readdirSync(baseMessagesDirPath)
Expand Down
7 changes: 0 additions & 7 deletions packages/docusaurus-types/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions packages/docusaurus-utils-common/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-utils-common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib",
"noEmitHelpers": false
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-utils-validation/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-utils-validation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__
2 changes: 2 additions & 0 deletions packages/docusaurus-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
"outDir": "lib"
}
Expand Down
11 changes: 4 additions & 7 deletions packages/docusaurus/.npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
src
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__

# production
/build

# generated files
.docusaurus
.cache-loader
src
6 changes: 6 additions & 0 deletions packages/lqip-loader/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
copyUntypedFiles.js
.tsbuildinfo
tsconfig*
__tests__

src