Browse Source

Remove scriptPathRegexpOverrides configuration option

pull/9/head
Nicolas Petton 2 years ago
parent
commit
62acbe87cd
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
4 changed files with 4 additions and 58 deletions
  1. +4
    -18
      server/helpers/workspace.js
  2. +0
    -14
      server/spec/helpers/workspace-spec.js
  3. +0
    -23
      sphinx-doc/debugger.rst
  4. +0
    -3
      sphinx-doc/setup.rst

+ 4
- 18
server/helpers/workspace.js View File

@ -34,6 +34,7 @@ const isProjectFile = path =>
basename(path) === projectFilename;
const isAbsolute = path => {
// Also test for Windows paths
return path.startsWith("/") || /^[a-zA-Z]\:[\\\/]/.test(path);
};
@ -69,37 +70,22 @@ const resolveRoot = conf => {
return resolve(dir);
};
const locateScript = (pathname, conf) => {
let overrides = conf.scriptPathRegexpOverrides || {};
for (let pattern of Object.keys(overrides)) {
let regex = new RegExp(pattern);
if (pathname.match(regex)) {
return pathname.replace(regex, overrides[pattern]);
}
}
return pathname;
};
const resolveUrl = (url, conf) => {
// In Node, script urls can be file paths. The path doesn't
// always exist either, so also check for a protocol when parsed
// as a URL.
if (isAbsolute(url) || !parse(url).protocol) {
// console.log(`Resolved to ${url}`);
return url;
}
let root = resolveRoot(conf);
let { protocol, pathname } = new URL(url);
// Always treat URLs using the file: protocol to have absolute pathnames.
let { protocol, pathname } = new URL(url);
if (protocol === "file:") {
return pathname;
}
return resolve(`${root}/${locateScript(pathname, conf)}`);
let root = resolveRoot(conf);
return resolve(`${root}/${pathname}`);
};
const expandRoot = (path, root = "") => {


+ 0
- 14
server/spec/helpers/workspace-spec.js View File

@ -209,7 +209,6 @@ describe("URL resolution", () => {
expect(resolveUrl(url, conf)).toEqual("/home/user/projects/foo/bar.js");
});
// Regression test for GH issue #161
it("does not transform the path when the file exists on Windows", () => {
let conf = {
@ -220,17 +219,4 @@ describe("URL resolution", () => {
expect(resolveUrl(url, conf)).toEqual(url);
});
it("supports script path regexp overrides", () => {
let conf = {
projectFile: "/home/user/projects/foo/.indium.json",
"scriptPathRegexpOverrides": {
"(/js/.*\\.js)/[0-9]+": "private$1"
}
};
let url = "http://localhost:3000/js/app.js/1234567890";
expect(resolveUrl(url, conf)).toEqual("/home/user/projects/foo/private/js/app.js");
});
});

+ 0
- 23
sphinx-doc/debugger.rst View File

@ -44,29 +44,6 @@ Overriding the ``sourceMapPathOverrides`` option will erase the default mapping.
.. TIP:: If sourcemaps do not seem to work, you can see how Indium resolves
sourcemap paths using ``M-x indium-list-sourcemap-sources``.
.. _scriptpaths:
Overriding script paths
~~~~~~~~~~~~~~~~~~~~~~~
If your application's script URLs don't correspond directly to where
their source code is located, you can use ``scriptPathRegexpOverrides`` to
tell Indium where to find the sources. It maps regular expressions to
Javascript substitution strings.
For example, if your project root is ``/home/user/projects/foo/``, and
the source code for http://localhost:3000/js/app.js/1234567890 is at
``/home/user/projects/foo/private/js/app.js``, you might set
``scriptPathRegexpOverrides`` to::
{
"(/js/.*\\.js)/[0-9]+": "private$1"
}
This removes the trailing slash and digits, and it adds "private" to
the beginning of the path below the project root.
Blackboxing scripts
-------------------


+ 0
- 3
sphinx-doc/setup.rst View File

@ -48,9 +48,6 @@ this ``.indium.json`` file is placed, but it can be overridden with the ``root``
]
}
Custom script path overrides can be set with ``scriptPathRegexpOverrides``. See
:ref:`scriptpaths` for more information on script paths and debugging.
Custom sourcemap path overrides can be set with ``sourceMapPathOverrides``. See
:ref:`sourcemaps` for more information on sourcemaps and debugging.


Loading…
Cancel
Save