Skip to content

Commit 4f4dc8e

Browse files
committed
add hash to monaco assets folder
1 parent dcb22ae commit 4f4dc8e

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

ui/frontend/editor/MonacoEditor.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import State from '../state';
66

77
import styles from './Editor.module.css';
88
import { config, grammar } from './rust_monaco_def';
9+
// @ts-ignore
10+
import monacoHash from "./monaco-editor.specialasset";
911

1012
const modeId = 'my-rust';
1113

@@ -42,7 +44,7 @@ const mapStateToProps = (state: State) => {
4244

4345
type MonacoEditorProps = CommonEditorProps & PropsFromState;
4446

45-
loader.config({ paths: { vs: '/assets/vs' } });
47+
loader.config({ paths: { vs: '/assets/' + monacoHash } });
4648

4749
const MonacoEditor: React.SFC<MonacoEditorProps> = props => {
4850
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/monaco-editor/min/vs

ui/frontend/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
"eslint": "^7.4.0",
5656
"eslint-plugin-react": "^7.14.3",
5757
"eslint-plugin-react-hooks": "^4.0.0",
58+
"folder-hash": "^4.0.1",
59+
"fs-extra": "^10.0.0",
5860
"glob": "^7.0.5",
5961
"html-webpack-plugin": "^5.2.0",
6062
"jest": "^27.0.0",
@@ -78,7 +80,7 @@
7880
"webpack-cli": "^4.5.0"
7981
},
8082
"engines": {
81-
"node": "^14.15.1"
83+
"node": "^14.15.1 || ^16.11.0"
8284
},
8385
"scripts": {
8486
"test": "jest",

ui/frontend/special-asset-loader.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require('path');
2+
const { hashElement } = require('folder-hash');
3+
const { copy } = require('fs-extra');
4+
5+
module.exports = async (source) => {
6+
const p = path.resolve(__dirname, source.trim());
7+
const { hash } = await hashElement(p);
8+
const urlh = hash.replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
9+
const name = `${path.basename(p)}-${urlh}`;
10+
await copy(p, path.resolve(__dirname, 'build', 'assets', name));
11+
return `export default "${name}"`;
12+
};

ui/frontend/webpack.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
77
const CompressionPlugin = require("compression-webpack-plugin");
88
const glob = require('glob');
99
const basename = require('basename');
10+
const path = require('path');
1011

1112
const thisPackage = require('./package.json');
1213
const devDependencies = Object.keys(thisPackage.devDependencies);
@@ -80,6 +81,10 @@ module.exports = function(_, argv) {
8081
exclude: /node_modules/,
8182
use: ['babel-loader', 'ts-loader'],
8283
},
84+
{
85+
test: /\.specialasset$/,
86+
use: path.resolve(__dirname, 'special-asset-loader.js'),
87+
},
8388
{
8489
test: /\.css$/,
8590
oneOf: [

ui/frontend/yarn.lock

+34-2
Original file line numberDiff line numberDiff line change
@@ -3121,6 +3121,15 @@ flatted@^3.1.0:
31213121
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
31223122
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==
31233123

3124+
folder-hash@^4.0.1:
3125+
version "4.0.1"
3126+
resolved "https://registry.yarnpkg.com/folder-hash/-/folder-hash-4.0.1.tgz#1603c46bdb899843e292ecdfca9e540dd22e1236"
3127+
integrity sha512-oF1MGtGAPezYJJRMRPzTwtDYwZdQ16UTnthsVAxjVZnlrQ36WuF6YxSgyZxnoUEK6JNPX+04FCFAkw5CzE5OMw==
3128+
dependencies:
3129+
debug "^4.1.1"
3130+
graceful-fs "~4.2.0"
3131+
minimatch "~3.0.4"
3132+
31243133
form-data@^3.0.0:
31253134
version "3.0.1"
31263135
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
@@ -3135,6 +3144,15 @@ fraction.js@^4.1.1:
31353144
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.1.1.tgz#ac4e520473dae67012d618aab91eda09bcb400ff"
31363145
integrity sha512-MHOhvvxHTfRFpF1geTK9czMIZ6xclsEor2wkIGYYq+PxcQqT7vStJqjhe6S1TenZrMZzo+wlqOufBDVepUEgPg==
31373146

3147+
fs-extra@^10.0.0:
3148+
version "10.0.0"
3149+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
3150+
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
3151+
dependencies:
3152+
graceful-fs "^4.2.0"
3153+
jsonfile "^6.0.1"
3154+
universalify "^2.0.0"
3155+
31383156
fs.realpath@^1.0.0:
31393157
version "1.0.0"
31403158
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -3287,7 +3305,7 @@ gonzales-pe@^4.3.0:
32873305
dependencies:
32883306
minimist "^1.2.5"
32893307

3290-
graceful-fs@^4.1.2, graceful-fs@^4.2.4:
3308+
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, graceful-fs@~4.2.0:
32913309
version "4.2.8"
32923310
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
32933311
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
@@ -4349,6 +4367,15 @@ json5@^1.0.1:
43494367
dependencies:
43504368
minimist "^1.2.0"
43514369

4370+
jsonfile@^6.0.1:
4371+
version "6.1.0"
4372+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
4373+
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
4374+
dependencies:
4375+
universalify "^2.0.0"
4376+
optionalDependencies:
4377+
graceful-fs "^4.1.6"
4378+
43524379
"jsx-ast-utils@^2.4.1 || ^3.0.0":
43534380
version "3.2.1"
43544381
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.1.tgz#720b97bfe7d901b927d87c3773637ae8ea48781b"
@@ -4673,7 +4700,7 @@ mini-css-extract-plugin@^2.0.0:
46734700
dependencies:
46744701
schema-utils "^3.1.0"
46754702

4676-
minimatch@^3.0.4:
4703+
minimatch@^3.0.4, minimatch@~3.0.4:
46774704
version "3.0.4"
46784705
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
46794706
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
@@ -6650,6 +6677,11 @@ universalify@^0.1.2:
66506677
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
66516678
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
66526679

6680+
universalify@^2.0.0:
6681+
version "2.0.0"
6682+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
6683+
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
6684+
66536685
uri-js@^4.2.2:
66546686
version "4.4.1"
66556687
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"

0 commit comments

Comments
 (0)