1 | /**
|
2 | * @fileoverview For scripts included in browser-window, this will automatically
|
3 | * inject the browser-window global scopes into the file.
|
4 | *
|
5 | * This Source Code Form is subject to the terms of the Mozilla Public
|
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | // -----------------------------------------------------------------------------
|
13 | // Rule Definition
|
14 | // -----------------------------------------------------------------------------
|
15 |
|
16 | var path = require("path");
|
17 | var helpers = require("../helpers");
|
18 | var browserWindowEnv = require("../environments/browser-window");
|
19 |
|
20 | module.exports = function(context) {
|
21 | // ---------------------------------------------------------------------------
|
22 | // Public
|
23 | // ---------------------------------------------------------------------------
|
24 |
|
25 | return {
|
26 | Program(node) {
|
27 | let filePath = helpers.getAbsoluteFilePath(context);
|
28 | let relativePath = path.relative(helpers.rootDir, filePath);
|
29 | // We need to translate the path on Windows, due to the change
|
30 | // from \ to /, and browserjsScripts assumes Posix.
|
31 | if (path.win32) {
|
32 | relativePath = relativePath.split(path.sep).join("/");
|
33 | }
|
34 |
|
35 | if (browserWindowEnv.browserjsScripts &&
|
36 | browserWindowEnv.browserjsScripts.includes(relativePath)) {
|
37 | for (let global in browserWindowEnv.globals) {
|
38 | helpers.addVarToScope(global, context.getScope(),
|
39 | browserWindowEnv.globals[global]);
|
40 | }
|
41 | }
|
42 | }
|
43 | };
|
44 | };
|