Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor-npm-package-…
Browse files Browse the repository at this point in the history
…process-facebookgh-5869
  • Loading branch information
etrepum committed Apr 20, 2024
2 parents ddb2e9c + 8fda1b4 commit 9789ceb
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 18 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/devtools-extension-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish DevTools extension to stores

on:
workflow_dispatch:

jobs:
release:
if: github.repository_owner == 'facebook'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Configure Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'npm'

- uses: actions/cache@v3
id: cache
with:
path: |
node_modules
~/.cache/ms-playwright
key: ${{ runner.os }}-v${{ secrets.CACHE_VERSION }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: Zip & submit to stores
run: npm run publish-extension
env:
EDGE_ACCESS_TOKEN_URL: ${{ secrets.EXTENSION_EDGE_ACCESS_TOKEN_URL }}
EDGE_CLIENT_SECRET: ${{ secrets.EXTENSION_EDGE_CLIENT_SECRET }}
EDGE_PRODUCT_ID: ${{ secrets.EXTENSION_EDGE_PRODUCT_ID }}
EDGE_CLIENT_ID: ${{ secrets.EXTENSION_EDGE_CLIENT_ID }}
FIREFOX_EXTENSION_ID: ${{ secrets.EXTENSION_FIREFOX_EXTENSION_ID }}
FIREFOX_JWT_ISSUER: ${{ secrets.EXTENSION_FIREFOX_JWT_ISSUER }}
FIREFOX_JWT_SECRET: ${{ secrets.EXTENSION_FIREFOX_JWT_SECRET }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm
e2e-screenshots
test-results
playwright-report
/SOURCE_CODE_REVIEW.md

npm-debug.log*

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"dev": "npm run dev --prefix packages/lexical-playground",
"start-test-server": "npm run preview --prefix packages/lexical-playground -- --port 4000",
"build": "node scripts/build.js",
"build-prod": "npm run clean && npm run build -- --prod",
"build-prod": "npm run clean && npm run build -- --prod && node ./scripts/validate-tsc-types.js",
"build-playground-prod": "npm run build-prod && npm run build-prod --prefix packages/lexical-playground",
"build-release": "npm run build-prod -- --release",
"build-release": "npm run build-prod -- --release && node ./scripts/validate-tsc-types.js",
"build-www": "npm run clean && npm run build -- --www && npm run build -- --www --prod && npm run prepare-www",
"build-types": "tsc -p ./tsconfig.build.json && node ./scripts/validate-tsc-types.js",
"clean": "node scripts/clean.js",
"extract-codes": "node scripts/build.js --codes",
"flow": "node ./scripts/check-flow-types.js",
Expand Down Expand Up @@ -101,6 +102,7 @@
"update-flowconfig": "node ./scripts/update-flowconfig",
"update-packages": "npm run update-version && npm run update-tsconfig && npm run update-flowconfig && npm run update-docs",
"postversion": "git checkout -b ${npm_package_version}__release && npm install && npm run update-version && npm run update-changelog && git add -A && git commit -m v${npm_package_version} && git tag -a v${npm_package_version} -m v${npm_package_version}",
"publish-extension": "npm run zip -w @lexical/devtools && npm run publish -w @lexical/devtools",
"release": "npm run prepare-release && node ./scripts/npm/release.js",
"size": "npm run build-prod && size-limit"
},
Expand Down
1 change: 1 addition & 0 deletions packages/lexical-devtools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ stats.html
stats-*.json
.wxt
web-ext.config.ts
.env.secrets

# Editor directories and files
.vscode/*
Expand Down
7 changes: 7 additions & 0 deletions packages/lexical-devtools/SOURCE_CODE_REVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Lexical Developer Tools review instructions:

1. Install latest LTS version of Node.js & Chrome
2. Use local copy of the source code or obtain one from https://github.com/facebook/lexical
3. Run `npm i`
4. Navigate to `/packages/lexical-devtools`
5. Run `npm run dev`
12 changes: 9 additions & 3 deletions packages/lexical-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
"dev": "wxt",
"dev:firefox": "wxt -b firefox",
"dev:edge": "wxt -b edge",
"build": "wxt build",
"build": "npm-run-all build:chrome build:firefox build:edge",
"build:chrome": "wxt build -b chrome",
"build:firefox": "wxt build -b firefox",
"zip": "wxt zip",
"zip:firefox": "wxt zip -b firefox",
"build:edge": "wxt build -b edge",
"zip": "npm-run-all zip:chrome zip:firefox zip:edge",
"zip:chrome": "wxt zip -b firefox",
"zip:firefox": "cp ./SOURCE_CODE_REVIEW.md ../.. && wxt zip -b firefox",
"zip:edge": "wxt zip -b edge",
"publish": "wxt submit --edge-zip .output/*-edge.zip --firefox-zip .output/*-firefox.zip --firefox-sources-zip .output/*-sources.zip",
"bundle-analyzer:open": "wxt build --analyze --analyze-open",
"compile": "tsc --noEmit",
"postinstall": "wxt prepare"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/lexical-devtools/wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import moduleResolution from '../shared/viteModuleResolution';
export default defineConfig({
debug: !!process.env.DEBUG_WXT,
manifest: (configEnv) => {
const browserName =
configEnv.browser.charAt(0).toUpperCase() + configEnv.browser.slice(1);

const manifestConf: UserManifest = {
author: 'Lexical',
description: `Adds Lexical debugging tools to the ${browserName} Developer Tools.`,
homepage_url: 'https://lexical.dev/',
icons: {
128: '/icon/128.png',
16: '/icon/16.png',
32: '/icon/32.png',
48: '/icon/48.png',
},
name: 'Lexical Developer Tools',
permissions: ['scripting', 'storage'],
web_accessible_resources: [
{
Expand Down Expand Up @@ -111,4 +118,7 @@ export default defineConfig({
],
},
}),
zip: {
sourcesRoot: path.resolve('../..'),
},
});
38 changes: 25 additions & 13 deletions packages/lexical-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,38 @@ import {
LexicalEditor,
LexicalNode,
} from 'lexical';
import {IS_FIREFOX} from 'shared/environment';
// This underscore postfixing is used as a hotfix so we do not
// export shared types from this module #5918
import {CAN_USE_DOM as CAN_USE_DOM_} from 'shared/canUseDOM';
import {
CAN_USE_BEFORE_INPUT as CAN_USE_BEFORE_INPUT_,
IS_ANDROID as IS_ANDROID_,
IS_ANDROID_CHROME as IS_ANDROID_CHROME_,
IS_APPLE as IS_APPLE_,
IS_APPLE_WEBKIT as IS_APPLE_WEBKIT_,
IS_CHROME as IS_CHROME_,
IS_FIREFOX as IS_FIREFOX_,
IS_IOS as IS_IOS_,
IS_SAFARI as IS_SAFARI_,
} from 'shared/environment';
import invariant from 'shared/invariant';
import normalizeClassNames from 'shared/normalizeClassNames';

export {default as markSelection} from './markSelection';
export {default as mergeRegister} from './mergeRegister';
export {default as positionNodeOnRange} from './positionNodeOnRange';
export {$splitNode, isHTMLAnchorElement, isHTMLElement} from 'lexical';
export {CAN_USE_DOM} from 'shared/canUseDOM';
export {
CAN_USE_BEFORE_INPUT,
IS_ANDROID,
IS_ANDROID_CHROME,
IS_APPLE,
IS_APPLE_WEBKIT,
IS_CHROME,
IS_FIREFOX,
IS_IOS,
IS_SAFARI,
} from 'shared/environment';
// Hotfix to export these with inlined types #5918
export const CAN_USE_BEFORE_INPUT: boolean = CAN_USE_BEFORE_INPUT_;
export const CAN_USE_DOM: boolean = CAN_USE_DOM_;
export const IS_ANDROID: boolean = IS_ANDROID_;
export const IS_ANDROID_CHROME: boolean = IS_ANDROID_CHROME_;
export const IS_APPLE: boolean = IS_APPLE_;
export const IS_APPLE_WEBKIT: boolean = IS_APPLE_WEBKIT_;
export const IS_CHROME: boolean = IS_CHROME_;
export const IS_FIREFOX: boolean = IS_FIREFOX_;
export const IS_IOS: boolean = IS_IOS_;
export const IS_SAFARI: boolean = IS_SAFARI_;

export type DFSNode = Readonly<{
depth: number;
Expand Down
88 changes: 88 additions & 0 deletions scripts/validate-tsc-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// @ts-check
'use strict';

const fs = require('fs-extra');
const glob = require('glob');
const ts = require('typescript');

const pretty = process.env.CI !== 'true';

/** @type {ts.FormatDiagnosticsHost} */
const diagnosticsHost = {
getCanonicalFileName: (fn) => fn,
getCurrentDirectory: () => './',
getNewLine: () => '\n',
};

/**
* Validate that the published .d.ts types do not have dependencies
* on any private module (currently shared/*).
*
* `process.exit(1)` on failure.
*/
function validateTscTypes() {
const dtsFilesPattern = './.ts-temp/{lexical,lexical-*}/**/*.d.ts';
const dtsFiles = glob.sync(dtsFilesPattern);
if (dtsFiles.length === 0) {
console.error(
`Missing ${dtsFilesPattern}, \`npm run build-prod\` or \`npm run build-release\` first`,
);
process.exit(1);
}
/** @type {ts.Diagnostic[]} */
const diagnostics = [];
for (const fn of dtsFiles) {
// console.log(fn);
const ast = ts.createSourceFile(
fn,
fs.readFileSync(fn, 'utf-8'),
ts.ScriptTarget.Latest,
);
const checkSpecifier = (/** @type {ts.Node | undefined} */ node) => {
if (!node || node.kind !== ts.SyntaxKind.StringLiteral) {
return;
}
const specifier = /** @type {import('typescript').StringLiteral} */ (
node
);
if (/^shared(\/|$)/.test(specifier.text)) {
const start = specifier.getStart(ast);
diagnostics.push({
category: ts.DiagnosticCategory.Error,
code: Infinity,
file: ast,
length: specifier.getEnd() - start,
messageText: `Published .d.ts files must not import private module '${specifier.text}'.`,
start,
});
}
};
ast.forEachChild((node) => {
if (node.kind === ts.SyntaxKind.ExportDeclaration) {
const exportNode =
/** @type {import('typescript').ExportDeclaration} */ (node);
checkSpecifier(exportNode.moduleSpecifier);
} else if (node.kind === ts.SyntaxKind.ImportDeclaration) {
const importNode =
/** @type {import('typescript').ImportDeclaration} */ (node);
checkSpecifier(importNode.moduleSpecifier);
}
});
}
if (diagnostics.length > 0) {
const msg = (
pretty ? ts.formatDiagnosticsWithColorAndContext : ts.formatDiagnostics
)(diagnostics, diagnosticsHost);
console.error(msg.replace(/ TSInfinity:/g, ':'));
process.exit(1);
}
}

validateTscTypes();

0 comments on commit 9789ceb

Please sign in to comment.