├── .gitattributes ├── .github └── workflows │ ├── ci.yml │ └── rich-navigation.yml.off ├── .gitignore ├── .gitmodules ├── .lsifrc.json ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── License.txt ├── README.md ├── SECURITY.md ├── ThirdPartyNotices.txt ├── package-lock.json ├── package.json ├── src ├── core │ ├── configuration.ts │ ├── env.ts │ ├── loaderEvents.ts │ ├── main.ts │ ├── moduleManager.ts │ ├── scriptLoader.ts │ ├── tsconfig.json │ └── utils.ts ├── loader.d.ts └── loader.js ├── tests ├── loader.test.js ├── loader.test.ts ├── ms-specific │ └── tests │ │ ├── fallback_double_fallback │ │ ├── _reporter.js │ │ ├── _test.js │ │ └── doublefoo2.js │ │ ├── fallback_original_works │ │ ├── _reporter.js │ │ ├── _test.js │ │ ├── a.js │ │ └── alt.js │ │ └── fallback_single_fallback │ │ ├── _reporter.js │ │ ├── _test.js │ │ └── foofallback.js ├── node-specific │ ├── _control.js │ ├── _loader.js │ ├── exporting-function │ │ ├── _test.js │ │ └── a.js │ ├── has-dirname │ │ ├── _test.js │ │ └── a.js │ ├── simple │ │ ├── _test.js │ │ └── folder │ │ │ └── foo.js │ ├── throwing-amd │ │ ├── _test.js │ │ └── a.js │ ├── what-is-this │ │ ├── _test.js │ │ └── a.js │ └── z-cached-data-create │ │ ├── _test.js │ │ ├── a.js │ │ └── cache-dir │ │ └── .gitkeep ├── qunit │ ├── qunit.css │ ├── qunit.d.ts │ └── qunit.js ├── run-tests.htm └── run-tests.js └── tsconfig.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Keep CRLF line terminators out of our text files, 2 | # regardless of the "core.autocrlf" setting. 3 | * text=auto 4 | 5 | # We already ask TypeScript to use this form for its output files; 6 | # ask git to do the same to avoid flip-flopping. 7 | *.js eol=lf 8 | *.ts.d eol=lf 9 | *.map eol=lf 10 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: CI 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-node@v2 12 | with: 13 | node-version: 14 14 | - run: npm ci 15 | - run: npm run compile 16 | - run: npm test 17 | -------------------------------------------------------------------------------- /.github/workflows/rich-navigation.yml.off: -------------------------------------------------------------------------------- 1 | name: "Rich Navigation Indexing" 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | richnav: 11 | runs-on: windows-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - uses: actions/setup-node@v2 16 | with: 17 | node-version: 14 18 | 19 | - name: Install dependencies 20 | run: npm install 21 | 22 | - uses: microsoft/RichCodeNavIndexer@v0.1 23 | with: 24 | languages: typescript 25 | repo-token: ${{ secrets.GITHUB_TOKEN }} 26 | typescriptVersion: 0.6.0-next.21 27 | configFiles: .lsifrc.json 28 | continue-on-error: true 29 | 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/user.json 2 | bin/ 3 | obj/ 4 | *.suo 5 | *.csproj.user 6 | *.js.map 7 | node_modules/ 8 | *.lsif -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests/amdjs-tests"] 2 | path = tests/amdjs-tests 3 | url = https://github.com/amdjs/amdjs-tests.git 4 | -------------------------------------------------------------------------------- /.lsifrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "./tsconfig.json", 3 | "out": "vscode-loader.lsif", 4 | "source": "./package.json", 5 | "package": "./package.json" 6 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceRoot}/tests/run-tests.js" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.trimTrailingWhitespace": true, 4 | "editor.tabSize": 4, 5 | "editor.insertSpaces": false, 6 | "editor.formatOnSave": true, 7 | "files.exclude": { 8 | ".git": true, 9 | "**/*.js": { 10 | "when": "**/core/$(basename).ts" 11 | } 12 | }, 13 | "typescript.tsdk": "./node_modules/typescript/lib", 14 | "git.branchProtection": ["main", "release/*"], 15 | "git.branchProtectionPrompt": "alwaysCommitToNewBranch", 16 | "git.branchRandomName.enable": true 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "compile-all", 9 | "problemMatcher": [ 10 | "$tsc" 11 | ] 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Microsoft Corporation 3 | 4 | All rights reserved. 5 | 6 | MIT License 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 9 | files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 10 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 16 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VSCode Loader 2 | 3 | An universal [Asynchronous Module Definition (AMD)](https://github.com/amdjs/amdjs-api/wiki/AMD) Loader developed primarily to load VSCode's sources. 4 | 5 | ## Supported environments 6 | * Edge, Firefox, Chrome, Safari 7 | * nodejs 8 | * electron (renderer & browser processes) 9 | In nodejs and electron, when loading a module, if it cannot be found with the AMD rules, it delegates loading them to the native `require`. 10 | 11 | ## Features 12 | 13 | * Runs factory methods as soon as dependencies are resolved. 14 | 15 | ## Using 16 | 17 | * In a browser environment: 18 | ```html 19 | 20 | 28 | ``` 29 | * In a node environment: 30 | ```javascript 31 | var loader = require('loader'); 32 | loader.config({ 33 | // ... 34 | }); 35 | loader(['an/amd/module'], function(value) { 36 | // code is loaded here 37 | }); 38 | ``` 39 | * Supported config options: 40 | * `baseUrl` - The prefix that will be aplied to all modules when they are resolved to a location 41 | * `paths` - Redirect rules for modules. The redirect rules will affect the module ids themselves 42 | * `config` - Per-module configuration 43 | * `catchError` - Catch errors when invoking the module factories 44 | * `recordStats` - Record statistics 45 | * `urlArgs` - The suffix that will be aplied to all modules when they are resolved to a location 46 | * `onError` - Callback that will be called when errors are encountered 47 | * `ignoreDuplicateModules` - The loader will issue warnings when duplicate modules are encountered. This list will inhibit those warnings if duplicate modules are expected. 48 | * `isBuild` - Flag to indicate if current execution is as part of a build. 49 | * `cspNonce` - Allows setting a Content Security Policy nonce value on script tags created by the loader. 50 | * `nodeRequire` - The main entry point node's require 51 | * `nodeInstrumenter` - An optional transformation applied to the source before it is loaded in node's vm 52 | 53 | ## Custom features 54 | 55 | * Recording loading statistics for detailed script loading times: 56 | ```javascript 57 | require.config({ 58 | recordStats: true 59 | }); 60 | // ... 61 | console.log(require.getRecorder().getEvents()); 62 | ``` 63 | 64 | * Extracting loading metadata for a bundler: 65 | ```javascript 66 | var loader = require('loader'); 67 | loader.config({ 68 | isBuild: true 69 | }); 70 | // ... 71 | console.log(loader.getBuildInfo()); 72 | ``` 73 | 74 | ## Testing 75 | 76 | To run the tests: 77 | * code loading in node: `npm run test` 78 | * amd spec tests, unit tests & code loading in browser: 79 | * `npm run simpleserver` 80 | * open `http://localhost:9999/tests/run-tests.htm` 81 | 82 | The project uses as a submodule the [AMD compliance tests](https://github.com/amdjs/amdjs-tests). The goal is to support as many tests without adding `eval()` or an equivalent. It is also not a goal to support loading CommonJS code: 83 | 84 | * Basic AMD Functionality (basic) 85 | * The Basic require() Method (require) 86 | * Anonymous Module Support (anon) 87 | * ~~CommonJS Compatibility (funcString)~~ 88 | * ~~CommonJS Compatibility with Named Modules (namedWrap)~~ 89 | * AMD Loader Plugins (plugins) 90 | * ~~Dynamic Plugins (pluginsDynamic)~~ 91 | * ~~Common Config: Packages~~ 92 | * ~~Common Config: Map~~ 93 | * ~~Common Config: Module~~ 94 | * Common Config: Path 95 | * ~~Common Config: Shim~~ 96 | 97 | ## Developing 98 | 99 | * Clone the repository 100 | * Run `git submodule init` 101 | * Run `git submodule update` 102 | * Run `npm install` 103 | * Compile in the background with `npm run watch1` and `npm run watch2` 104 | 105 | ## Code of Conduct 106 | 107 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 108 | 109 | ## License 110 | [MIT](https://github.com/microsoft/vscode-loader/blob/master/License.txt) 111 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION 2 | Do Not Translate or Localize 3 | 4 | This project incorporates material from the project(s) listed below (collectively, "Third Party Code"). 5 | Microsoft is not the original author of the Third Party Code. The original copyright notice and license 6 | under which Microsoft received such Third Party Code are set out below. This Third Party Code is licensed 7 | to you under their original license terms set forth below. Microsoft reserves all other rights not 8 | expressly granted, whether by implication, estoppel or otherwise. 9 | 10 | The following files/folders contain third party software used for development-time testing: 11 | 12 | ========================================================================================================= 13 | tests/qunit/** 14 | --------------------------------------------------------------------------------------------------------- 15 | The MIT License (MIT) 16 | 17 | Copyright 2013 jQuery Foundation and other contributors 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | ========================================================================================================= 37 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@vscode/loader", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "@vscode/loader", 9 | "version": "1.0.0", 10 | "license": "MIT", 11 | "devDependencies": { 12 | "typescript": "^4.9.5", 13 | "yaserver": "^0.4.0" 14 | } 15 | }, 16 | "node_modules/typescript": { 17 | "version": "4.9.5", 18 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", 19 | "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", 20 | "dev": true, 21 | "bin": { 22 | "tsc": "bin/tsc", 23 | "tsserver": "bin/tsserver" 24 | }, 25 | "engines": { 26 | "node": ">=4.2.0" 27 | } 28 | }, 29 | "node_modules/yaserver": { 30 | "version": "0.4.0", 31 | "resolved": "https://registry.npmjs.org/yaserver/-/yaserver-0.4.0.tgz", 32 | "integrity": "sha512-98Vj4sgqB1fLcpf2wK7h3dFCaabISHU9CXZHaAx3QLkvTTCD31MzMcNbw5V5jZFBK7ffkFqfWig6B20KQt4wtA==", 33 | "dev": true, 34 | "bin": { 35 | "yaserver": "bin/yaserver" 36 | } 37 | } 38 | }, 39 | "dependencies": { 40 | "typescript": { 41 | "version": "4.9.5", 42 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", 43 | "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", 44 | "dev": true 45 | }, 46 | "yaserver": { 47 | "version": "0.4.0", 48 | "resolved": "https://registry.npmjs.org/yaserver/-/yaserver-0.4.0.tgz", 49 | "integrity": "sha512-98Vj4sgqB1fLcpf2wK7h3dFCaabISHU9CXZHaAx3QLkvTTCD31MzMcNbw5V5jZFBK7ffkFqfWig6B20KQt4wtA==", 50 | "dev": true 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@vscode/loader", 3 | "version": "1.0.0", 4 | "description": "An universal AMD Loader", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "watch1": "tsc -w -p src/core/tsconfig.json", 11 | "watch2": "tsc -w -p tsconfig.json", 12 | "compile": "tsc -p src/core/tsconfig.json && tsc -p tsconfig.json", 13 | "test": "node ./tests/run-tests.js", 14 | "simpleserver": "yaserver --root ./ --port 9999" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/microsoft/vscode-loader.git" 19 | }, 20 | "author": "Microsoft Corporation", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/microsoft/vscode-loader/issues" 24 | }, 25 | "homepage": "https://github.com/microsoft/vscode-loader#readme", 26 | "devDependencies": { 27 | "typescript": "^4.9.5", 28 | "yaserver": "^0.4.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/core/configuration.ts: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------------------- 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for license information. 4 | *--------------------------------------------------------------------------------------------*/ 5 | 6 | namespace AMDLoader { 7 | 8 | export interface AnnotatedLoadingError extends Error { 9 | phase: 'loading'; 10 | moduleId: string; 11 | neededBy: string[]; 12 | } 13 | 14 | export interface AnnotatedFactoryError extends Error { 15 | phase: 'factory'; 16 | moduleId: string; 17 | neededBy: string[]; 18 | } 19 | 20 | export interface AnnotatedValidationError extends Error { 21 | phase: 'configuration'; 22 | } 23 | 24 | export type AnnotatedError = AnnotatedLoadingError | AnnotatedFactoryError | AnnotatedValidationError; 25 | 26 | export function ensureError(err: any): T { 27 | if (err instanceof Error) { 28 | return err; 29 | } 30 | const result = new Error(err.message || String(err) || 'Unknown Error'); 31 | if (err.stack) { 32 | result.stack = err.stack; 33 | } 34 | return result; 35 | } 36 | 37 | /** 38 | * The signature for the loader's AMD "define" function. 39 | */ 40 | export interface IDefineFunc { 41 | (id: 'string', dependencies: string[], callback: any): void; 42 | (id: 'string', callback: any): void; 43 | (dependencies: string[], callback: any): void; 44 | (callback: any): void; 45 | 46 | amd: { 47 | jQuery: boolean; 48 | }; 49 | } 50 | 51 | /** 52 | * The signature for the loader's AMD "require" function. 53 | */ 54 | export interface IRequireFunc { 55 | (module: string): any; 56 | (config: any): void; 57 | (modules: string[], callback: Function): void; 58 | (modules: string[], callback: Function, errorback: (err: any) => void): void; 59 | 60 | config(params: IConfigurationOptions, shouldOverwrite?: boolean): void; 61 | 62 | getConfig(): IConfigurationOptions; 63 | 64 | /** 65 | * Non standard extension to reset completely the loader state. This is used for running amdjs tests 66 | */ 67 | reset(): void; 68 | 69 | /** 70 | * Non standard extension to fetch loader state for building purposes. 71 | */ 72 | getBuildInfo(): IBuildModuleInfo[] | null; 73 | 74 | /** 75 | * Non standard extension to fetch loader events 76 | */ 77 | getStats(): LoaderEvent[]; 78 | 79 | /** 80 | * The define function 81 | */ 82 | define(id: 'string', dependencies: string[], callback: any): void; 83 | define(id: 'string', callback: any): void; 84 | define(dependencies: string[], callback: any): void; 85 | define(callback: any): void; 86 | 87 | moduleManager?: ModuleManager; 88 | } 89 | 90 | export interface IModuleConfiguration { 91 | [key: string]: any; 92 | } 93 | 94 | export interface INodeRequire { 95 | (nodeModule: string): any; 96 | main: { 97 | filename: string; 98 | }; 99 | } 100 | 101 | export interface INodeCachedDataConfiguration { 102 | /** 103 | * Directory path in which cached is stored. 104 | */ 105 | path: string; 106 | /** 107 | * Seed when generating names of cache files. 108 | */ 109 | seed?: string; 110 | /** 111 | * Optional delay for filesystem write/delete operations 112 | */ 113 | writeDelay?: number; 114 | }; 115 | 116 | export interface IConfigurationOptions { 117 | /** 118 | * Allow module ids to end with .js 119 | */ 120 | allowJsExtension?: boolean; 121 | /** 122 | * The prefix that will be aplied to all modules when they are resolved to a location 123 | */ 124 | baseUrl?: string; 125 | /** 126 | * Redirect rules for modules. The redirect rules will affect the module ids themselves 127 | */ 128 | paths?: { [path: string]: any; }; 129 | /** 130 | * Per-module configuration 131 | */ 132 | config?: { [moduleId: string]: IModuleConfiguration }; 133 | /** 134 | * Catch errors when invoking the module factories 135 | */ 136 | catchError?: boolean; 137 | /** 138 | * Record statistics 139 | */ 140 | recordStats?: boolean; 141 | /** 142 | * The suffix that will be aplied to all modules when they are resolved to a location 143 | */ 144 | urlArgs?: string; 145 | /** 146 | * Callback that will be called when errors are encountered 147 | */ 148 | onError?: (err: AnnotatedError) => void; 149 | /** 150 | * The loader will issue warnings when duplicate modules are encountered. 151 | * This list will inhibit those warnings if duplicate modules are expected. 152 | */ 153 | ignoreDuplicateModules?: string[]; 154 | /** 155 | * Flag to indicate if current execution is as part of a build. Used by plugins 156 | */ 157 | isBuild?: boolean; 158 | /** 159 | * Normally, during a build, no module factories are invoked. This can be used 160 | * to forcefully execute a module's factory. 161 | */ 162 | buildForceInvokeFactory?: { [moduleId: string]: boolean; } 163 | /** 164 | * Content Security Policy nonce value used to load child scripts. 165 | */ 166 | cspNonce?: string; 167 | /** 168 | * If running inside an electron renderer, prefer using 20 | 66 | 67 | 68 | 69 | 70 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /tests/run-tests.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fs = require('fs'); 3 | var control = require('./node-specific/_control'); 4 | var loader = require('./node-specific/_loader'); 5 | 6 | var ROOT_DIR = path.join(__dirname, 'node-specific'); 7 | 8 | // Discover tests 9 | var entries = fs.readdirSync(ROOT_DIR); 10 | 11 | entries = entries.filter(function(entry) { 12 | var fullPath = path.join(ROOT_DIR, entry); 13 | return fs.statSync(fullPath).isDirectory(); 14 | }); 15 | 16 | var currentTest = null; 17 | 18 | var colors = (function() { 19 | 20 | var _colors = { 21 | black: "30", 22 | red: "31", 23 | green: "32", 24 | yellow: "33", 25 | blue: "34", 26 | magenta: "35", 27 | cyan: "36", 28 | white: "37", 29 | }; 30 | 31 | 32 | var r = {}; 33 | 34 | Object.keys(_colors).forEach(function(colorName) { 35 | var colorCode = _colors[colorName]; 36 | r[colorName] = function(str) { 37 | return '\x1b[' + colorCode + 'm' + str + '\x1b[0m'; 38 | } 39 | }); 40 | 41 | return r; 42 | })(); 43 | 44 | var okCnt = 0, totalCnt = entries.length; 45 | 46 | function runTest(err) { 47 | if (currentTest) { 48 | if (err) { 49 | console.log(colors.red('[ERROR ] ' + currentTest + ': \n'), err); 50 | } else { 51 | okCnt++; 52 | console.log(colors.green('[PASSED ] ' + currentTest + '.')); 53 | } 54 | } 55 | 56 | if (entries.length > 0) { 57 | currentTest = entries.shift(); 58 | var testModulePath = path.join(ROOT_DIR, currentTest, '_test'); 59 | loader.reset(); 60 | try { 61 | require(testModulePath); 62 | } catch (err) { 63 | runTest(err); 64 | return; 65 | } 66 | } else { 67 | var str = '[FINISHED] ' + okCnt + '/' + totalCnt + ' passed.'; 68 | if (okCnt !== totalCnt) { 69 | str = colors.red(str); 70 | } else { 71 | str = colors.green(str); 72 | } 73 | console.log(str); 74 | } 75 | } 76 | 77 | control.setContinuation(runTest); 78 | runTest(null); 79 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "newLine": "LF", 5 | "noUnusedLocals": false 6 | }, 7 | "files": [ 8 | "src/loader.d.ts", 9 | "tests/qunit/qunit.d.ts", 10 | "tests/loader.test.ts" 11 | ], 12 | "exclude": [ 13 | "node_modules" 14 | ] 15 | } 16 | --------------------------------------------------------------------------------