2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-11 17:51:58 +08:00
|
|
|
"use strict";
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-08 12:02:55 +08:00
|
|
|
const Dependency = require("../Dependency");
|
2018-07-23 23:33:29 +08:00
|
|
|
const DependencyTemplate = require("../DependencyTemplate");
|
2021-03-11 22:04:53 +08:00
|
|
|
|
2021-09-27 22:43:34 +08:00
|
|
|
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
2021-03-11 22:04:53 +08:00
|
|
|
/** @typedef {import("../Module")} Module */
|
2024-06-11 00:21:03 +08:00
|
|
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
2025-08-21 21:23:01 +08:00
|
|
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
2023-04-12 03:22:51 +08:00
|
|
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
|
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
2021-03-11 22:04:53 +08:00
|
|
|
|
2017-01-08 12:02:55 +08:00
|
|
|
class ModuleDependency extends Dependency {
|
2018-05-04 00:57:02 +08:00
|
|
|
/**
|
|
|
|
* @param {string} request request path which needs resolving
|
|
|
|
*/
|
2017-01-08 12:02:55 +08:00
|
|
|
constructor(request) {
|
|
|
|
super();
|
|
|
|
this.request = request;
|
|
|
|
this.userRequest = request;
|
2025-08-21 21:23:01 +08:00
|
|
|
/** @type {Range | undefined} */
|
2018-07-23 23:33:29 +08:00
|
|
|
this.range = undefined;
|
2022-03-28 23:51:48 +08:00
|
|
|
this._context = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string | undefined} a request context
|
|
|
|
*/
|
|
|
|
getContext() {
|
|
|
|
return this._context;
|
2017-01-08 12:02:55 +08:00
|
|
|
}
|
|
|
|
|
2018-07-25 15:33:48 +08:00
|
|
|
/**
|
|
|
|
* @returns {string | null} an identifier to merge equal requests
|
|
|
|
*/
|
2017-11-19 07:22:38 +08:00
|
|
|
getResourceIdentifier() {
|
2025-09-18 20:37:40 +08:00
|
|
|
return `context${this._context || ""}|module${this.request}`;
|
2017-01-08 12:02:55 +08:00
|
|
|
}
|
2018-10-09 20:30:59 +08:00
|
|
|
|
2021-09-27 22:43:34 +08:00
|
|
|
/**
|
|
|
|
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
|
|
|
*/
|
|
|
|
couldAffectReferencingModule() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-11 22:04:53 +08:00
|
|
|
/**
|
|
|
|
* @param {string} context context directory
|
2025-05-13 21:03:58 +08:00
|
|
|
* @returns {Module} ignored module
|
2021-03-11 22:04:53 +08:00
|
|
|
*/
|
|
|
|
createIgnoredModule(context) {
|
2025-08-04 22:38:42 +08:00
|
|
|
const RawModule = require("../RawModule");
|
|
|
|
|
2025-07-10 21:23:05 +08:00
|
|
|
const module = new RawModule(
|
2021-03-11 22:04:53 +08:00
|
|
|
"/* (ignored) */",
|
|
|
|
`ignored|${context}|${this.request}`,
|
|
|
|
`${this.request} (ignored)`
|
|
|
|
);
|
2025-07-10 21:23:05 +08:00
|
|
|
module.factoryMeta = { sideEffectFree: true };
|
|
|
|
return module;
|
2021-03-11 22:04:53 +08:00
|
|
|
}
|
|
|
|
|
2023-04-12 03:22:51 +08:00
|
|
|
/**
|
|
|
|
* @param {ObjectSerializerContext} context context
|
|
|
|
*/
|
2018-10-09 20:30:59 +08:00
|
|
|
serialize(context) {
|
|
|
|
const { write } = context;
|
|
|
|
write(this.request);
|
|
|
|
write(this.userRequest);
|
2022-03-28 23:51:48 +08:00
|
|
|
write(this._context);
|
2018-10-09 20:30:59 +08:00
|
|
|
write(this.range);
|
|
|
|
super.serialize(context);
|
|
|
|
}
|
|
|
|
|
2023-04-12 03:22:51 +08:00
|
|
|
/**
|
|
|
|
* @param {ObjectDeserializerContext} context context
|
|
|
|
*/
|
2018-10-09 20:30:59 +08:00
|
|
|
deserialize(context) {
|
|
|
|
const { read } = context;
|
|
|
|
this.request = read();
|
|
|
|
this.userRequest = read();
|
2022-03-28 23:51:48 +08:00
|
|
|
this._context = read();
|
2018-10-09 20:30:59 +08:00
|
|
|
this.range = read();
|
|
|
|
super.deserialize(context);
|
|
|
|
}
|
2013-01-31 01:49:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
ModuleDependency.Template = DependencyTemplate;
|
|
|
|
|
2017-01-08 12:02:55 +08:00
|
|
|
module.exports = ModuleDependency;
|