This repository was archived by the owner on Oct 1, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +57
-44
lines changed
Expand file tree Collapse file tree 9 files changed +57
-44
lines changed Original file line number Diff line number Diff line change 3131 "node" : " >= 5.0"
3232 },
3333 "dependencies" : {
34- "@paulcbetts/mime-types" : " ^2.1.10" ,
3534 "btoa" : " ^1.1.2" ,
3635 "debug-electron" : " 0.0.1" ,
3736 "lru-cache" : " ^4.0.1" ,
Original file line number Diff line number Diff line change 1- import mimeTypes from '@paulcbetts/mime-types' ;
21import fs from 'fs' ;
32import zlib from 'zlib' ;
43import path from 'path' ;
54import { pfs , pzlib } from './promise' ;
65
6+ import mimeTypes from './mime-types' ;
77import { forAllFiles , forAllFilesSync } from './for-all-files' ;
88import CompileCache from './compile-cache' ;
99import FileChangedCache from './file-change-cache' ;
1010import ReadOnlyCompiler from './read-only-compiler' ;
1111
1212const d = require ( 'debug-electron' ) ( 'electron-compile:compiler-host' ) ;
1313
14- require ( './rig-mime-types' ) . init ( ) ;
15-
1614// This isn't even my
1715const finalForms = {
1816 'text/javascript' : true ,
Original file line number Diff line number Diff line change 1+ import path from 'path' ;
2+
3+ const MimeTypesToExtensions = {
4+ 'application/javascript' : [ 'js' , 'es6' ] ,
5+ 'text/less' : [ 'less' ] ,
6+ 'text/stylus' : [ 'stylus' ] ,
7+ 'text/jsx' : [ 'jsx' ] ,
8+ 'text/cjsx' : [ 'cjsx' ] ,
9+ 'text/coffeescript' : [ 'coffee' , 'litcoffee' ] ,
10+ 'text/typescript' : [ 'ts' ] ,
11+ 'text/tsx' : [ 'tsx' ] ,
12+ 'text/cson' : [ 'cson' ] ,
13+ 'text/html' : [ 'html' , 'htm' ] ,
14+ 'text/jade' : [ 'jade' ] ,
15+ 'text/plain' : [ 'txt' ] ,
16+ 'image/svg+xml' : [ 'svg' ] ,
17+ } ;
18+
19+ const ExtensionsToMimeTypes = { } ;
20+ for ( const mimetype of Object . keys ( MimeTypesToExtensions ) ) {
21+ for ( const ext of MimeTypesToExtensions [ mimetype ] ) {
22+ ExtensionsToMimeTypes [ ext ] = mimetype ;
23+ }
24+ }
25+
26+ class MimeTypes {
27+ lookup ( filepath ) {
28+ const ext = path . extname ( filepath ) ;
29+ return ExtensionsToMimeTypes [ ext . slice ( 1 ) ] || false ;
30+ }
31+
32+ extension ( mimeType ) {
33+ return this . extensions ( mimeType ) [ 0 ] ;
34+ }
35+
36+ extensions ( mimeType ) {
37+ return MimeTypesToExtensions [ mimeType ] || [ ] ;
38+ }
39+
40+ }
41+ export default new MimeTypes ( ) ;
Original file line number Diff line number Diff line change 11import url from 'url' ;
22import fs from 'fs' ;
3- import mime from '@paulcbetts /mime-types' ;
3+ import mime from '. /mime-types' ;
44
55const magicWords = "__magic__file__to__help__electron__compile.js" ;
66
Original file line number Diff line number Diff line change 1- import mimeTypes from '@paulcbetts /mime-types' ;
1+ import mimeTypes from '. /mime-types' ;
22
33/**
4- * Initializes the node.js hook that allows us to intercept files loaded by
5- * node.js and rewrite them. This method along with {@link initializeProtocolHook}
6- * are the top-level methods that electron-compile actually uses to intercept
4+ * Initializes the node.js hook that allows us to intercept files loaded by
5+ * node.js and rewrite them. This method along with {@link initializeProtocolHook}
6+ * are the top-level methods that electron-compile actually uses to intercept
77 * code that Electron loads.
8- *
8+ *
99 * @param {CompilerHost } compilerHost The compiler host to use for compilation.
10- */
10+ */
1111export default function registerRequireExtension ( compilerHost ) {
1212 Object . keys ( compilerHost . compilersByMimeType ) . forEach ( ( mimeType ) => {
13- let ext = mimeTypes . extension ( mimeType ) ;
14-
15- require . extensions [ `. ${ ext } ` ] = ( module , filename ) => {
16- let { code } = compilerHost . compileSync ( filename ) ;
17- module . _compile ( code , filename ) ;
18- } ;
13+ mimeTypes . extensions ( mimeType ) . forEach ( ( ext ) => {
14+ require . extensions [ `. ${ ext } ` ] = ( module , filename ) => {
15+ let { code } = compilerHost . compileSync ( filename ) ;
16+ module . _compile ( code , filename ) ;
17+ } ;
18+ } ) ;
1919 } ) ;
2020}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import path from 'path';
44import fs from 'fs' ;
55import rimraf from 'rimraf' ;
66import mkdirp from 'mkdirp' ;
7- import mimeTypes from '@paulcbetts /mime-types' ;
7+ import mimeTypes from '.. /mime-types' ;
88import FileChangeCache from '../src/file-change-cache' ;
99import CompilerHost from '../src/compiler-host' ;
1010
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import './support';
33import pify from 'pify' ;
44import fs from 'fs' ;
55import path from 'path' ;
6- import mimeTypes from '@paulcbetts /mime-types' ;
6+ import mimeTypes from '.. /mime-types' ;
77
88const pfs = pify ( fs ) ;
99
Original file line number Diff line number Diff line change @@ -13,8 +13,6 @@ global.AssertionError = chai.AssertionError;
1313global . Assertion = chai . Assertion ;
1414global . assert = chai . assert ;
1515
16- require ( '../src/rig-mime-types' ) . init ( ) ;
17-
1816global . compilersByMimeType = allCompilerClasses . reduce ( ( acc , x ) => {
1917 acc = acc || { } ;
2018
You can’t perform that action at this time.
0 commit comments