Commit 8b92ab94 authored by Tim van der Lippe's avatar Tim van der Lippe Committed by Commit Bot

Migrate workspaces/ to ESM

- Rename Workspace.js to WorkspaceImpl.js to not name clash with
workspace.js in the Grit localization generation.

Bug: 1006759
Change-Id: I56a496d866e4a453cd3ef84a24c29f8baa296876
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847280
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703716}
parent 33abbe9b
...@@ -785,10 +785,7 @@ all_devtools_files = [ ...@@ -785,10 +785,7 @@ all_devtools_files = [
"front_end/worker_main/module.json", "front_end/worker_main/module.json",
"front_end/worker_service/module.json", "front_end/worker_service/module.json",
"front_end/worker_service/ServiceDispatcher.js", "front_end/worker_service/ServiceDispatcher.js",
"front_end/workspace/FileManager.js",
"front_end/workspace/module.json", "front_end/workspace/module.json",
"front_end/workspace/UISourceCode.js",
"front_end/workspace/Workspace.js",
"front_end/workspace_diff/WorkspaceDiff.js", "front_end/workspace_diff/WorkspaceDiff.js",
"front_end/workspace_diff/module.json", "front_end/workspace_diff/module.json",
] ]
...@@ -847,6 +844,10 @@ lighthouse_locale_files = [ ...@@ -847,6 +844,10 @@ lighthouse_locale_files = [
all_devtools_files += lighthouse_locale_files all_devtools_files += lighthouse_locale_files
all_devtools_modules = [ all_devtools_modules = [
"front_end/workspace/workspace.js",
"front_end/workspace/WorkspaceImpl.js",
"front_end/workspace/UISourceCode.js",
"front_end/workspace/FileManager.js",
"front_end/services/services.js", "front_end/services/services.js",
"front_end/services/ServiceManager.js", "front_end/services/ServiceManager.js",
"front_end/sdk/sdk.js", "front_end/sdk/sdk.js",
...@@ -1194,6 +1195,10 @@ application_templates = [ ...@@ -1194,6 +1195,10 @@ application_templates = [
] ]
copied_devtools_modules = [ copied_devtools_modules = [
"$resources_out_dir/workspace/workspace.js",
"$resources_out_dir/workspace/WorkspaceImpl.js",
"$resources_out_dir/workspace/UISourceCode.js",
"$resources_out_dir/workspace/FileManager.js",
"$resources_out_dir/services/services.js", "$resources_out_dir/services/services.js",
"$resources_out_dir/services/ServiceManager.js", "$resources_out_dir/services/ServiceManager.js",
"$resources_out_dir/sdk/sdk.js", "$resources_out_dir/sdk/sdk.js",
......
...@@ -324,8 +324,9 @@ Persistence.NetworkPersistenceManager = class extends Common.Object { ...@@ -324,8 +324,9 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
const url = Common.ParsedURL.urlWithoutHash(uiSourceCode.url()); const url = Common.ParsedURL.urlWithoutHash(uiSourceCode.url());
this._networkUISourceCodeForEncodedPath.set(this._encodedPathFromUrl(url), uiSourceCode); this._networkUISourceCodeForEncodedPath.set(this._encodedPathFromUrl(url), uiSourceCode);
const fileSystemUISourceCode = const fileSystemUISourceCode = this._project.uiSourceCodeForURL(
this._project.uiSourceCodeForURL(this._project.fileSystemPath() + '/' + this._encodedPathFromUrl(url)); /** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem} */ (this._project).fileSystemPath() + '/' +
this._encodedPathFromUrl(url));
if (!fileSystemUISourceCode) { if (!fileSystemUISourceCode) {
return; return;
} }
...@@ -465,7 +466,8 @@ Persistence.NetworkPersistenceManager = class extends Common.Object { ...@@ -465,7 +466,8 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
if (!this._active || (method !== 'GET' && method !== 'POST')) { if (!this._active || (method !== 'GET' && method !== 'POST')) {
return; return;
} }
const path = this._project.fileSystemPath() + '/' + this._encodedPathFromUrl(interceptedRequest.request.url); const path = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem} */ (this._project).fileSystemPath() +
'/' + this._encodedPathFromUrl(interceptedRequest.request.url);
const fileSystemUISourceCode = this._project.uiSourceCodeForURL(path); const fileSystemUISourceCode = this._project.uiSourceCodeForURL(path);
if (!fileSystemUISourceCode) { if (!fileSystemUISourceCode) {
return; return;
......
...@@ -88,7 +88,9 @@ Persistence.WorkspaceSettingsTab = class extends UI.VBox { ...@@ -88,7 +88,9 @@ Persistence.WorkspaceSettingsTab = class extends UI.VBox {
} }
const networkPersistenceProject = Persistence.networkPersistenceManager.project(); const networkPersistenceProject = Persistence.networkPersistenceManager.project();
if (networkPersistenceProject && if (networkPersistenceProject &&
Persistence.isolatedFileSystemManager.fileSystem(networkPersistenceProject.fileSystemPath()) === fileSystem) { Persistence.isolatedFileSystemManager.fileSystem(
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem} */ (networkPersistenceProject)
.fileSystemPath()) === fileSystem) {
return; return;
} }
const element = this._renderFileSystem(fileSystem); const element = this._renderFileSystem(fileSystem);
......
...@@ -12,3 +12,4 @@ import './sdk/sdk.js'; ...@@ -12,3 +12,4 @@ import './sdk/sdk.js';
import './ui/ui.js'; import './ui/ui.js';
import './services/services.js'; import './services/services.js';
import './workspace/workspace.js';
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
/** /**
* @unrestricted * @unrestricted
*/ */
Workspace.FileManager = class extends Common.Object { export default class FileManager extends Common.Object {
constructor() { constructor() {
super(); super();
/** @type {!Map<string, function(?{fileSystemPath: (string|undefined)})>} */ /** @type {!Map<string, function(?{fileSystemPath: (string|undefined)})>} */
...@@ -101,16 +101,28 @@ Workspace.FileManager = class extends Common.Object { ...@@ -101,16 +101,28 @@ Workspace.FileManager = class extends Common.Object {
*/ */
_appendedToURL(event) { _appendedToURL(event) {
const url = /** @type {string} */ (event.data); const url = /** @type {string} */ (event.data);
this.dispatchEventToListeners(Workspace.FileManager.Events.AppendedToURL, url); this.dispatchEventToListeners(Events.AppendedToURL, url);
} }
}; }
/** @enum {symbol} */ /** @enum {symbol} */
Workspace.FileManager.Events = { export const Events = {
AppendedToURL: Symbol('AppendedToURL') AppendedToURL: Symbol('AppendedToURL')
}; };
/* Legacy exported object */
self.Workspace = self.Workspace || {};
/* Legacy exported object */
Workspace = Workspace || {};
/** @constructor */
Workspace.FileManager = FileManager;
/** @enum {symbol} */
Workspace.FileManager.Events = Events;
/** /**
* @type {?Workspace.FileManager} * @type {?FileManager}
*/ */
Workspace.fileManager; Workspace.fileManager;
\ No newline at end of file
...@@ -30,83 +30,92 @@ ...@@ -30,83 +30,92 @@
/** /**
* @interface * @interface
*/ */
Workspace.ProjectSearchConfig = function() {}; export class ProjectSearchConfig {
Workspace.ProjectSearchConfig.prototype = {
/** /**
* @return {string} * @return {string}
*/ */
query() {}, query() {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
ignoreCase() {}, ignoreCase() {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
isRegex() {}, isRegex() {
}
/** /**
* @return {!Array.<string>} * @return {!Array.<string>}
*/ */
queries() {}, queries() {
}
/** /**
* @param {string} filePath * @param {string} filePath
* @return {boolean} * @return {boolean}
*/ */
filePathMatchesFileQuery(filePath) {} filePathMatchesFileQuery(filePath) {
}; }
}
/** /**
* @interface * @interface
*/ */
Workspace.Project = function() {}; export class Project {
Workspace.Project.prototype = {
/** /**
* @return {!Workspace.Workspace} * @return {!WorkspaceImpl}
*/ */
workspace() {}, workspace() {
}
/** /**
* @return {string} * @return {string}
*/ */
id() {}, id() {
}
/** /**
* @return {string} * @return {string}
*/ */
type() {}, type() {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
isServiceProject() {}, isServiceProject() {
}
/** /**
* @return {string} * @return {string}
*/ */
displayName() {}, displayName() {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
* @return {!Promise<?Workspace.UISourceCodeMetadata>} * @return {!Promise<?Workspace.UISourceCodeMetadata>}
*/ */
requestMetadata(uiSourceCode) {}, requestMetadata(uiSourceCode) {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
* @param {function(?string,boolean)} callback * @param {function(?string,boolean)} callback
*/ */
requestFileContent(uiSourceCode, callback) {}, requestFileContent(uiSourceCode, callback) {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
canSetFileContent() {}, canSetFileContent() {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
...@@ -114,42 +123,49 @@ Workspace.Project.prototype = { ...@@ -114,42 +123,49 @@ Workspace.Project.prototype = {
* @param {boolean} isBase64 * @param {boolean} isBase64
* @return {!Promise} * @return {!Promise}
*/ */
setFileContent(uiSourceCode, newContent, isBase64) {}, setFileContent(uiSourceCode, newContent, isBase64) {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
* @return {string} * @return {string}
*/ */
fullDisplayName(uiSourceCode) {}, fullDisplayName(uiSourceCode) {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
* @return {string} * @return {string}
*/ */
mimeType(uiSourceCode) {}, mimeType(uiSourceCode) {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
canRename() {}, canRename() {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
* @param {string} newName * @param {string} newName
* @param {function(boolean, string=, string=, !Common.ResourceType=)} callback * @param {function(boolean, string=, string=, !Common.ResourceType=)} callback
*/ */
rename(uiSourceCode, newName, callback) {}, rename(uiSourceCode, newName, callback) {
}
/** /**
* @param {string} path * @param {string} path
*/ */
excludeFolder(path) {}, excludeFolder(path) {
}
/** /**
* @param {string} path * @param {string} path
* @return {boolean} * @return {boolean}
*/ */
canExcludeFolder(path) {}, canExcludeFolder(path) {
}
/** /**
* @param {string} path * @param {string} path
...@@ -158,19 +174,23 @@ Workspace.Project.prototype = { ...@@ -158,19 +174,23 @@ Workspace.Project.prototype = {
* @param {boolean=} isBase64 * @param {boolean=} isBase64
* @return {!Promise<?Workspace.UISourceCode>} * @return {!Promise<?Workspace.UISourceCode>}
*/ */
createFile(path, name, content, isBase64) {}, createFile(path, name, content, isBase64) {
}
/** /**
* @return {boolean} * @return {boolean}
*/ */
canCreateFile() {}, canCreateFile() {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
*/ */
deleteFile(uiSourceCode) {}, deleteFile(uiSourceCode) {
}
remove() {}, remove() {
}
/** /**
* @param {!Workspace.UISourceCode} uiSourceCode * @param {!Workspace.UISourceCode} uiSourceCode
...@@ -179,37 +199,42 @@ Workspace.Project.prototype = { ...@@ -179,37 +199,42 @@ Workspace.Project.prototype = {
* @param {boolean} isRegex * @param {boolean} isRegex
* @return {!Promise<!Array<!Common.ContentProvider.SearchMatch>>} * @return {!Promise<!Array<!Common.ContentProvider.SearchMatch>>}
*/ */
searchInFileContent(uiSourceCode, query, caseSensitive, isRegex) {}, searchInFileContent(uiSourceCode, query, caseSensitive, isRegex) {
}
/** /**
* @param {!Workspace.ProjectSearchConfig} searchConfig * @param {!ProjectSearchConfig} searchConfig
* @param {!Array.<string>} filesMathingFileQuery * @param {!Array.<string>} filesMathingFileQuery
* @param {!Common.Progress} progress * @param {!Common.Progress} progress
* @return {!Promise<!Array<string>>} * @return {!Promise<!Array<string>>}
*/ */
findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress) {}, findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress) {
}
/** /**
* @param {!Common.Progress} progress * @param {!Common.Progress} progress
*/ */
indexContent(progress) {}, indexContent(progress) {
}
/** /**
* @param {string} url * @param {string} url
* @return {?Workspace.UISourceCode} * @return {?Workspace.UISourceCode}
*/ */
uiSourceCodeForURL(url) {}, uiSourceCodeForURL(url) {
}
/** /**
* @return {!Array.<!Workspace.UISourceCode>} * @return {!Array.<!Workspace.UISourceCode>}
*/ */
uiSourceCodes() {} uiSourceCodes() {
}; }
}
/** /**
* @enum {string} * @enum {string}
*/ */
Workspace.projectTypes = { export const projectTypes = {
Debugger: 'debugger', Debugger: 'debugger',
Formatter: 'formatter', Formatter: 'formatter',
Network: 'network', Network: 'network',
...@@ -221,9 +246,9 @@ Workspace.projectTypes = { ...@@ -221,9 +246,9 @@ Workspace.projectTypes = {
/** /**
* @unrestricted * @unrestricted
*/ */
Workspace.ProjectStore = class { export class ProjectStore {
/** /**
* @param {!Workspace.Workspace} workspace * @param {!WorkspaceImpl} workspace
* @param {string} id * @param {string} id
* @param {!Workspace.projectTypes} type * @param {!Workspace.projectTypes} type
* @param {string} displayName * @param {string} displayName
...@@ -239,7 +264,7 @@ Workspace.ProjectStore = class { ...@@ -239,7 +264,7 @@ Workspace.ProjectStore = class {
/** @type {!Array.<!Workspace.UISourceCode>} */ /** @type {!Array.<!Workspace.UISourceCode>} */
this._uiSourceCodesList = []; this._uiSourceCodesList = [];
this._project = /** @type {!Workspace.Project} */ (this); this._project = /** @type {!Project} */ (this);
} }
/** /**
...@@ -264,7 +289,7 @@ Workspace.ProjectStore = class { ...@@ -264,7 +289,7 @@ Workspace.ProjectStore = class {
} }
/** /**
* @return {!Workspace.Workspace} * @return {!WorkspaceImpl}
*/ */
workspace() { workspace() {
return this._workspace; return this._workspace;
...@@ -290,7 +315,7 @@ Workspace.ProjectStore = class { ...@@ -290,7 +315,7 @@ Workspace.ProjectStore = class {
} }
this._uiSourceCodesMap.set(url, {uiSourceCode: uiSourceCode, index: this._uiSourceCodesList.length}); this._uiSourceCodesMap.set(url, {uiSourceCode: uiSourceCode, index: this._uiSourceCodesList.length});
this._uiSourceCodesList.push(uiSourceCode); this._uiSourceCodesList.push(uiSourceCode);
this._workspace.dispatchEventToListeners(Workspace.Workspace.Events.UISourceCodeAdded, uiSourceCode); this._workspace.dispatchEventToListeners(Events.UISourceCodeAdded, uiSourceCode);
return true; return true;
} }
...@@ -310,7 +335,7 @@ Workspace.ProjectStore = class { ...@@ -310,7 +335,7 @@ Workspace.ProjectStore = class {
movedEntry.index = entry.index; movedEntry.index = entry.index;
this._uiSourceCodesList.splice(this._uiSourceCodesList.length - 1, 1); this._uiSourceCodesList.splice(this._uiSourceCodesList.length - 1, 1);
this._uiSourceCodesMap.delete(url); this._uiSourceCodesMap.delete(url);
this._workspace.dispatchEventToListeners(Workspace.Workspace.Events.UISourceCodeRemoved, entry.uiSourceCode); this._workspace.dispatchEventToListeners(Events.UISourceCodeRemoved, entry.uiSourceCode);
} }
removeProject() { removeProject() {
...@@ -347,15 +372,15 @@ Workspace.ProjectStore = class { ...@@ -347,15 +372,15 @@ Workspace.ProjectStore = class {
this._uiSourceCodesMap.set(newPath, value); this._uiSourceCodesMap.set(newPath, value);
this._uiSourceCodesMap.delete(oldPath); this._uiSourceCodesMap.delete(oldPath);
} }
}; }
/** /**
* @unrestricted * @unrestricted
*/ */
Workspace.Workspace = class extends Common.Object { export default class WorkspaceImpl extends Common.Object {
constructor() { constructor() {
super(); super();
/** @type {!Map<string, !Workspace.Project>} */ /** @type {!Map<string, !Project>} */
this._projects = new Map(); this._projects = new Map();
this._hasResourceContentTrackingExtensions = false; this._hasResourceContentTrackingExtensions = false;
} }
...@@ -399,32 +424,32 @@ Workspace.Workspace = class extends Common.Object { ...@@ -399,32 +424,32 @@ Workspace.Workspace = class extends Common.Object {
} }
/** /**
* @param {!Workspace.Project} project * @param {!Project} project
*/ */
addProject(project) { addProject(project) {
console.assert(!this._projects.has(project.id()), `A project with id ${project.id()} already exists!`); console.assert(!this._projects.has(project.id()), `A project with id ${project.id()} already exists!`);
this._projects.set(project.id(), project); this._projects.set(project.id(), project);
this.dispatchEventToListeners(Workspace.Workspace.Events.ProjectAdded, project); this.dispatchEventToListeners(Events.ProjectAdded, project);
} }
/** /**
* @param {!Workspace.Project} project * @param {!Project} project
*/ */
_removeProject(project) { _removeProject(project) {
this._projects.delete(project.id()); this._projects.delete(project.id());
this.dispatchEventToListeners(Workspace.Workspace.Events.ProjectRemoved, project); this.dispatchEventToListeners(Events.ProjectRemoved, project);
} }
/** /**
* @param {string} projectId * @param {string} projectId
* @return {?Workspace.Project} * @return {?Project}
*/ */
project(projectId) { project(projectId) {
return this._projects.get(projectId) || null; return this._projects.get(projectId) || null;
} }
/** /**
* @return {!Array.<!Workspace.Project>} * @return {!Array.<!Project>}
*/ */
projects() { projects() {
return this._projects.valuesArray(); return this._projects.valuesArray();
...@@ -432,7 +457,7 @@ Workspace.Workspace = class extends Common.Object { ...@@ -432,7 +457,7 @@ Workspace.Workspace = class extends Common.Object {
/** /**
* @param {string} type * @param {string} type
* @return {!Array.<!Workspace.Project>} * @return {!Array.<!Project>}
*/ */
projectsForType(type) { projectsForType(type) {
function filterByType(project) { function filterByType(project) {
...@@ -465,10 +490,10 @@ Workspace.Workspace = class extends Common.Object { ...@@ -465,10 +490,10 @@ Workspace.Workspace = class extends Common.Object {
hasResourceContentTrackingExtensions() { hasResourceContentTrackingExtensions() {
return this._hasResourceContentTrackingExtensions; return this._hasResourceContentTrackingExtensions;
} }
}; }
/** @enum {symbol} */ /** @enum {symbol} */
Workspace.Workspace.Events = { export const Events = {
UISourceCodeAdded: Symbol('UISourceCodeAdded'), UISourceCodeAdded: Symbol('UISourceCodeAdded'),
UISourceCodeRemoved: Symbol('UISourceCodeRemoved'), UISourceCodeRemoved: Symbol('UISourceCodeRemoved'),
UISourceCodeRenamed: Symbol('UISourceCodeRenamed'), UISourceCodeRenamed: Symbol('UISourceCodeRenamed'),
...@@ -479,7 +504,31 @@ Workspace.Workspace.Events = { ...@@ -479,7 +504,31 @@ Workspace.Workspace.Events = {
ProjectRemoved: Symbol('ProjectRemoved') ProjectRemoved: Symbol('ProjectRemoved')
}; };
/* Legacy exported object */
self.Workspace = self.Workspace || {};
/* Legacy exported object */
Workspace = Workspace || {};
/** @constructor */
Workspace.Workspace = WorkspaceImpl;
/** @enum {symbol} */
Workspace.Workspace.Events = Events;
/** @interface */
Workspace.ProjectSearchConfig = ProjectSearchConfig;
/** @interface */
Workspace.Project = Project;
/** @enum {string} */
Workspace.projectTypes = projectTypes;
/** @constructor */
Workspace.ProjectStore = ProjectStore;
/** /**
* @type {!Workspace.Workspace} * @type {!WorkspaceImpl}
*/ */
Workspace.workspace; Workspace.workspace;
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
"host", "host",
"platform" "platform"
], ],
"scripts": [ "scripts": [],
"modules": [
"workspace.js",
"FileManager.js", "FileManager.js",
"UISourceCode.js", "UISourceCode.js",
"Workspace.js" "WorkspaceImpl.js"
] ]
} }
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as FileManager from './FileManager.js';
import * as UISourceCode from './UISourceCode.js';
import * as Workspace from './WorkspaceImpl.js';
export {
FileManager,
UISourceCode,
Workspace,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment