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

avoid bundling unnecesary languages, except graphql/json #3285

Merged
merged 61 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bf99ea8
simplify `monaco-graphql-react-vite`, fix sending variables
dimaMachina Apr 17, 2023
d10fc0d
Merge branch 'main' into fix-monaco-react
dimaMachina Jun 24, 2023
081122d
review fixes
dimaMachina Jun 24, 2023
9332d33
refactor
dimaMachina Jun 24, 2023
85ebde3
refactor
dimaMachina Jun 24, 2023
38efaa8
update deps
dimaMachina Jun 24, 2023
ac48d56
add symlink to react-vite
dimaMachina Jun 24, 2023
ee63adb
more symlinks
dimaMachina Jun 24, 2023
438db76
more
dimaMachina Jun 24, 2023
aa0af7f
temp
dimaMachina Jun 24, 2023
7d30f46
more
dimaMachina Jun 24, 2023
711c5e9
more
dimaMachina Jun 24, 2023
dc57e50
more
dimaMachina Jun 24, 2023
44d3e6d
ok
dimaMachina Jun 24, 2023
f7ac458
refactor
dimaMachina Jun 24, 2023
590ae38
refactor
dimaMachina Jun 24, 2023
a4c2ea8
dry
dimaMachina Jun 24, 2023
8d79e44
Merge branch 'main' into fix-monaco-react
dimaMachina Jun 24, 2023
2d088eb
Merge branch 'fix-monaco-react' into example/next
dimaMachina Jun 24, 2023
72ad83e
temp
dimaMachina Jun 24, 2023
d45d2f4
temp
dimaMachina Jun 24, 2023
fc4fad2
temp
dimaMachina Jun 24, 2023
35bdcee
lint
dimaMachina Jun 24, 2023
427c07e
more work
dimaMachina Jun 24, 2023
924a168
fix examples imports
dimaMachina Jun 24, 2023
edd64cb
temp
dimaMachina Jun 24, 2023
895b5a1
Merge branch 'example/next' into min-monaco
dimaMachina Jun 24, 2023
3ca0359
add tests
dimaMachina Jun 25, 2023
fe695c2
add changeset
dimaMachina Jun 25, 2023
4cd441a
make lint passes
dimaMachina Jun 25, 2023
0e25aa3
Merge branch 'main' into min-monaco
dimaMachina Jun 25, 2023
99e2d0d
tweaks
dimaMachina Jun 25, 2023
2c88c7d
Update .changeset/gold-nails-share.md
Jun 25, 2023
c061960
tweaks
dimaMachina Jun 25, 2023
0eb94c5
tweaks
dimaMachina Jun 25, 2023
7a96de9
Update .changeset/gold-nails-share.md
Jun 26, 2023
387485e
Update .eslintrc.js
Jun 26, 2023
2b90abb
Update packages/monaco-graphql/src/monaco-editor.ts
Jun 26, 2023
a340fa6
Update packages/monaco-graphql/src/monaco-editor.ts
Jun 26, 2023
426994f
Merge branch 'main' into min-monaco
dimaMachina Jun 26, 2023
ea6bb11
tests now passes
dimaMachina Jun 26, 2023
a22cf42
refactor monaco webpack
dimaMachina Jun 26, 2023
9065a11
patch types
dimaMachina Jun 26, 2023
f5eb346
add docs
dimaMachina Jun 26, 2023
0e866a7
add docs
dimaMachina Jun 26, 2023
7e9c2d4
better eslint
dimaMachina Jun 26, 2023
3a38f5e
this should fixes tests on ci
dimaMachina Jun 26, 2023
00821b2
fix `Invalid option in build() call: "watch"` in newly esbuild
dimaMachina Jun 26, 2023
4a1d9ed
fixes
dimaMachina Jun 26, 2023
48dc2a0
Update packages/monaco-graphql/README.md
Jun 26, 2023
a593f55
Update packages/monaco-graphql/README.md
Jun 26, 2023
56e1e72
Update .eslintrc.js
Jun 26, 2023
084227f
Update .eslintrc.js
Jun 26, 2023
52ab5a1
Update packages/monaco-graphql/README.md
Jun 26, 2023
3c1e7da
Update packages/monaco-graphql/README.md
Jun 26, 2023
486a8db
apply suggestions + more timeout
dimaMachina Jun 26, 2023
dd4ec76
tweak ascii characters to make ci pass
dimaMachina Jun 26, 2023
d3ad48e
more timeout..
dimaMachina Jun 26, 2023
ddbd8cb
debug what's wrong
dimaMachina Jun 27, 2023
ee52a1b
fix monaco-graphql when process.env.CI is set
dimaMachina Jun 27, 2023
24b72a1
Merge branch 'main' into min-monaco
acao Jul 5, 2023
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
5 changes: 5 additions & 0 deletions .changeset/gold-nails-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'monaco-graphql': minor
---

avoid bundling unnecessary languages — import `monaco-graphql/esm/monaco-editor` instead of `monaco-editor` to reduce your bundle size, as that imports only `graphql` and `json` languages and leaves out `ts`, `css`, `html`, and much more
23 changes: 22 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const RESTRICTED_IMPORTS = [
{ name: 'graphql/type/definition', message: 'use `graphql`' },
{ name: 'graphql/type/directives', message: 'use `graphql`' },
{ name: 'graphql/version', message: 'use `graphql`' },
{
name: 'monaco-editor',
message:
'`monaco-editor` imports all languages; use `monaco-graphql/esm/monaco-editor` instead to import only `json` and `graphql` languages',
},
];

module.exports = {
Expand Down Expand Up @@ -249,7 +254,6 @@ module.exports = {
'unicorn/prefer-dom-node-remove': 'error',
// ECMAScript 6 (http://eslint.org/docs/rules/#ecmascript-6)
'arrow-body-style': 'off',
'no-duplicate-imports': 'off',
'@typescript-eslint/no-restricted-imports': [
'error',
...RESTRICTED_IMPORTS,
Expand Down Expand Up @@ -431,6 +435,21 @@ module.exports = {
'promise/prefer-await-to-then': 'error',
},
},
{
// Monaco-GraphQL rules
files: ['packages/monaco-graphql/**'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'error',
...RESTRICTED_IMPORTS.filter(({ name }) => name !== 'monaco-editor'),
{
name: 'monaco-editor',
message:
'`monaco-editor` imports all languages; use locale `monaco-editor.ts` instead to import only `json` and `graphql` languages',
},
],
},
},
{
// Parsing Markdown/MDX
files: ['**/*.{md,mdx}'],
Expand All @@ -442,6 +461,7 @@ module.exports = {
},
},
{
// ❗ALWAYS LAST
// Rules for codeblocks inside Markdown/MDX
files: ['**/*.{md,mdx}/*.{js,jsx,ts,tsx}'],
rules: {
Expand All @@ -454,6 +474,7 @@ module.exports = {
'react-hooks/rules-of-hooks': 'off',
'@arthurgeron/react-usememo/require-usememo': 'off',
'sonar/no-dead-store': 'off',
'@typescript-eslint/no-restricted-imports': 'off',
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- run: yarn install --frozen-lockfile --immutable

- name: Run Unit Tests
run: yarn test:ci --coverage
run: yarn test:ci

- uses: codecov/codecov-action@v3
with:
Expand Down
7 changes: 4 additions & 3 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ sonarjs
svgr
typedoc
vite
vitest
vitejs
wonka
urql

// identifiers used in code and configs
acmerc
Expand Down Expand Up @@ -123,7 +125,6 @@ marko
matchingbracket
middlewares
modulemap
myschema
newhope
nocheck
nocursor
Expand Down Expand Up @@ -152,11 +153,9 @@ streamable
subword
testid
testonly
typeof
unfocus
unnormalized
unsubscribable
urql
vash
websockets

Expand Down Expand Up @@ -221,3 +220,5 @@ typeahead
typeaheads
unparsable
randomthing
codicon
edcore
2 changes: 1 addition & 1 deletion examples/monaco-graphql-nextjs/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { editor, Uri } from 'monaco-editor';
import { editor, Uri } from 'monaco-graphql/esm/monaco-editor';
import { initializeMode } from 'monaco-graphql/esm/initializeMode';

type ModelType = 'operations' | 'variables' | 'response';
Expand Down
22 changes: 14 additions & 8 deletions examples/monaco-graphql-nextjs/src/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ReactElement, useEffect, useRef, useState } from 'react';
import { getIntrospectionQuery, IntrospectionQuery } from 'graphql';
import { editor, KeyMod, KeyCode, languages } from 'monaco-editor';
import {
editor,
KeyMod,
KeyCode,
languages,
} from 'monaco-graphql/esm/monaco-editor';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import * as JSONC from 'jsonc-parser';
import {
Expand Down Expand Up @@ -69,16 +74,17 @@ languages.json.jsonDefaults.setDiagnosticsOptions({
trailingCommas: 'ignore',
});

type CodeEditor = editor.IStandaloneCodeEditor | null;

export default function Editor(): ReactElement {
const operationsRef = useRef<HTMLDivElement>(null);
const variablesRef = useRef<HTMLDivElement>(null);
const responseRef = useRef<HTMLDivElement>(null);
const [operationsEditor, setOperationsEditor] = useState<CodeEditor>(null);
const [variablesEditor, setVariablesEditor] = useState<CodeEditor>(null);
const [responseEditor, setResponseEditor] = useState<CodeEditor>(null);
const [schema, setSchema] = useState<IntrospectionQuery | null>(null);
const [operationsEditor, setOperationsEditor] =
useState<editor.IStandaloneCodeEditor>();
const [variablesEditor, setVariablesEditor] =
useState<editor.IStandaloneCodeEditor>();
const [responseEditor, setResponseEditor] =
useState<editor.IStandaloneCodeEditor>();
const [schema, setSchema] = useState<IntrospectionQuery>();
const [loading, setLoading] = useState(false);
/**
* Create the models & editors
Expand Down Expand Up @@ -137,7 +143,7 @@ export default function Editor(): ReactElement {
setLoading(true);
void getSchema().then(async introspectionJSON => {
MONACO_GRAPHQL_API.setSchemaConfig([
{ introspectionJSON, uri: 'myschema.graphql' },
{ introspectionJSON, uri: 'my-schema.graphql' },
]);
setSchema(introspectionJSON);
setLoading(false);
Expand Down
3 changes: 1 addition & 2 deletions examples/monaco-graphql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"jsonc-parser": "3.2.0",
"monaco-editor": "^0.36.0",
"monaco-graphql": "^1.2.4",
"prettier": "^2.8.4"
"prettier": "3.0.0-alpha.12"
},
"devDependencies": {
"@babel/core": "^7.21.0",
Expand All @@ -24,7 +24,6 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@types/prettier": "^2.7.2",
"@webpack-cli/serve": "^2.0.1",
"babel-loader": "^9.1.2",
"cross-env": "^7.0.2",
Expand Down
98 changes: 43 additions & 55 deletions examples/monaco-graphql-webpack/src/editors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as monaco from 'monaco-editor';
import { editor, Uri } from 'monaco-graphql/esm/monaco-editor';

const GRAPHQL_LANGUAGE_ID = 'graphql';

Expand Down Expand Up @@ -35,80 +35,68 @@ const schemaSdlString = localStorage.getItem('schema-sdl') ?? '';
const THEME = 'vs-dark';

export function createEditors() {
const variablesModel = monaco.editor.createModel(
const variablesModel = editor.createModel(
variablesString,
'json',
monaco.Uri.file('/1/variables.json'),
Uri.file('/1/variables.json'),
);

const variablesEditor = monaco.editor.create(
document.getElementById('variables'),
{
model: variablesModel,
language: 'json',
formatOnPaste: true,
formatOnType: true,
theme: THEME,
comments: {
insertSpace: true,
ignoreEmptyLines: true,
},
const variablesEditor = editor.create(document.getElementById('variables'), {
model: variablesModel,
language: 'json',
formatOnPaste: true,
formatOnType: true,
theme: THEME,
comments: {
insertSpace: true,
ignoreEmptyLines: true,
},
);
});

const operationModel = monaco.editor.createModel(
const operationModel = editor.createModel(
operationString,
GRAPHQL_LANGUAGE_ID,
monaco.Uri.file('/1/operation.graphql'),
Uri.file('/1/operation.graphql'),
);

const operationEditor = monaco.editor.create(
document.getElementById('operation'),
{
model: operationModel,
formatOnPaste: true,
formatOnType: true,
folding: true,
theme: THEME,
language: GRAPHQL_LANGUAGE_ID,
},
);
const operationEditor = editor.create(document.getElementById('operation'), {
model: operationModel,
formatOnPaste: true,
formatOnType: true,
folding: true,
theme: THEME,
language: GRAPHQL_LANGUAGE_ID,
});

const schemaModel = monaco.editor.createModel(
const schemaModel = editor.createModel(
schemaSdlString,
GRAPHQL_LANGUAGE_ID,
monaco.Uri.file('/1/schema.graphqls'),
Uri.file('/1/schema.graphqls'),
);

const schemaEditor = monaco.editor.create(
document.getElementById('schema-sdl'),
{
model: schemaModel,
formatOnPaste: true,
formatOnType: true,
folding: true,
theme: THEME,
language: GRAPHQL_LANGUAGE_ID,
},
);
const schemaEditor = editor.create(document.getElementById('schema-sdl'), {
model: schemaModel,
formatOnPaste: true,
formatOnType: true,
folding: true,
theme: THEME,
language: GRAPHQL_LANGUAGE_ID,
});

const resultsModel = monaco.editor.createModel(
const resultsModel = editor.createModel(
resultsString,
'json',
monaco.Uri.file('/1/results.json'),
Uri.file('/1/results.json'),
);

const resultsEditor = monaco.editor.create(
document.getElementById('results'),
{
model: resultsModel,
language: 'json',
theme: THEME,
wordWrap: 'on',
readOnly: true,
showFoldingControls: 'always',
},
);
const resultsEditor = editor.create(document.getElementById('results'), {
model: resultsModel,
language: 'json',
theme: THEME,
wordWrap: 'on',
readOnly: true,
showFoldingControls: 'always',
});

return {
operationEditor,
Expand Down
10 changes: 5 additions & 5 deletions examples/monaco-graphql-webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global netlify */

import * as monaco from 'monaco-editor';
import { editor, KeyMod, KeyCode } from 'monaco-graphql/esm/monaco-editor';
import * as JSONC from 'jsonc-parser';
import { initializeMode } from 'monaco-graphql/esm/initializeMode';

Expand Down Expand Up @@ -181,28 +181,28 @@ async function render() {
/**
* Add an editor operation to the command palette & keyboard shortcuts
*/
const opAction: monaco.editor.IActionDescriptor = {
const opAction: editor.IActionDescriptor = {
id: 'graphql-run',
label: 'Run Operation',
contextMenuOrder: 0,
contextMenuGroupId: 'graphql',
keybindings: [
// eslint-disable-next-line no-bitwise
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
KeyMod.CtrlCmd | KeyCode.Enter,
],
run: operationHandler,
};

/**
* Add a reload operation to the command palette & keyboard shortcuts
*/
const reloadAction: monaco.editor.IActionDescriptor = {
const reloadAction: editor.IActionDescriptor = {
id: 'graphql-reload',
label: 'Reload Schema',
contextMenuOrder: 0,
contextMenuGroupId: 'graphql',
keybindings: [
monaco.KeyMod.CtrlCmd | monaco.KeyCode?.KeyR, // eslint-disable-line no-bitwise
KeyMod.CtrlCmd | KeyCode?.KeyR, // eslint-disable-line no-bitwise
],
async run() {
await schemaFetcher.loadSchema();
Expand Down
4 changes: 2 additions & 2 deletions examples/monaco-graphql-webpack/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
parse,
buildASTSchema,
} from 'graphql';
import type { SchemaConfig } from 'monaco-graphql/src/typings';
import { Uri } from 'monaco-editor';
import type { SchemaConfig } from 'monaco-graphql';
import { Uri } from 'monaco-graphql/esm/monaco-editor';

const SCHEMA_URL = 'https://api.github.com/graphql';
const API_TOKEN = localStorage.getItem('ghapi') || null;
Expand Down
Loading