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

Migrate persistence/ to ESM

- Rename Persistence.js to PersistenceImpl to avoid a name clash with
the namespace

Bug: 1006759
Change-Id: I330bd680c8a92984c4a75a0614efa78b4f1e1ea2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845715
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: default avatarPaul Lewis <aerotwist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704200}
parent f19b3bfa
......@@ -466,20 +466,9 @@ if (!external_devtools_frontend) {
"front_end/performance_test_runner/module.json",
"front_end/performance_test_runner/TimelineDataTestRunner.js",
"front_end/performance_test_runner/TimelineTestRunner.js",
"front_end/persistence/Automapping.js",
"front_end/persistence/editFileSystemView.css",
"front_end/persistence/EditFileSystemView.js",
"front_end/persistence/FileSystemWorkspaceBinding.js",
"front_end/persistence/IsolatedFileSystem.js",
"front_end/persistence/IsolatedFileSystemManager.js",
"front_end/persistence/module.json",
"front_end/persistence/NetworkPersistenceManager.js",
"front_end/persistence/Persistence.js",
"front_end/persistence/PersistenceActions.js",
"front_end/persistence/PersistenceUtils.js",
"front_end/persistence/PlatformFileSystem.js",
"front_end/persistence/workspaceSettingsTab.css",
"front_end/persistence/WorkspaceSettingsTab.js",
"front_end/platform/module.json",
"front_end/product_registry/BadgePool.js",
"front_end/product_registry/ProductRegistry.js",
......@@ -832,6 +821,18 @@ if (!external_devtools_frontend) {
all_devtools_files += lighthouse_locale_files
all_devtools_modules = [
"front_end/persistence/persistence.js",
"front_end/persistence/WorkspaceSettingsTab.js",
"front_end/persistence/PlatformFileSystem.js",
"front_end/persistence/PersistenceUtils.js",
"front_end/persistence/PersistenceImpl.js",
"front_end/persistence/PersistenceActions.js",
"front_end/persistence/NetworkPersistenceManager.js",
"front_end/persistence/IsolatedFileSystemManager.js",
"front_end/persistence/IsolatedFileSystem.js",
"front_end/persistence/FileSystemWorkspaceBinding.js",
"front_end/persistence/EditFileSystemView.js",
"front_end/persistence/Automapping.js",
"front_end/components/components.js",
"front_end/components/TargetDetachedDialog.js",
"front_end/components/Reload.js",
......@@ -1208,6 +1209,18 @@ if (!external_devtools_frontend) {
]
copied_devtools_modules = [
"$resources_out_dir/persistence/persistence.js",
"$resources_out_dir/persistence/WorkspaceSettingsTab.js",
"$resources_out_dir/persistence/PlatformFileSystem.js",
"$resources_out_dir/persistence/PersistenceUtils.js",
"$resources_out_dir/persistence/PersistenceImpl.js",
"$resources_out_dir/persistence/PersistenceActions.js",
"$resources_out_dir/persistence/NetworkPersistenceManager.js",
"$resources_out_dir/persistence/IsolatedFileSystemManager.js",
"$resources_out_dir/persistence/IsolatedFileSystem.js",
"$resources_out_dir/persistence/FileSystemWorkspaceBinding.js",
"$resources_out_dir/persistence/EditFileSystemView.js",
"$resources_out_dir/persistence/Automapping.js",
"$resources_out_dir/components/components.js",
"$resources_out_dir/components/TargetDetachedDialog.js",
"$resources_out_dir/components/Reload.js",
......
......@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.Automapping = class {
export default class Automapping {
/**
* @param {!Workspace.Workspace} workspace
* @param {function(!Persistence.AutomappingStatus)} onStatusAdded
* @param {function(!Persistence.AutomappingStatus)} onStatusRemoved
* @param {function(!AutomappingStatus)} onStatusAdded
* @param {function(!AutomappingStatus)} onStatusRemoved
*/
constructor(workspace, onStatusAdded, onStatusRemoved) {
this._workspace = workspace;
this._onStatusAdded = onStatusAdded;
this._onStatusRemoved = onStatusRemoved;
/** @type {!Set<!Persistence.AutomappingStatus>} */
/** @type {!Set<!AutomappingStatus>} */
this._statuses = new Set();
this._statusSymbol = Symbol('Automapping.Status');
this._processingPromiseSymbol = Symbol('Automapping.ProcessingPromise');
......@@ -25,9 +25,9 @@ Persistence.Automapping = class {
this._sweepThrottler = new Common.Throttler(100);
const pathEncoder = new Persistence.PathEncoder();
this._filesIndex = new Persistence.Automapping.FilePathIndex(pathEncoder);
this._projectFoldersIndex = new Persistence.Automapping.FolderIndex(pathEncoder);
this._activeFoldersIndex = new Persistence.Automapping.FolderIndex(pathEncoder);
this._filesIndex = new FilePathIndex(pathEncoder);
this._projectFoldersIndex = new FolderIndex(pathEncoder);
this._activeFoldersIndex = new FolderIndex(pathEncoder);
/** @type {!Array<function(!Workspace.UISourceCode):boolean>} */
this._interceptors = [];
......@@ -73,7 +73,7 @@ Persistence.Automapping = class {
this._sweepThrottler.schedule(sweepUnmapped.bind(this));
/**
* @this {Persistence.Automapping}
* @this {Automapping}
* @return {!Promise}
*/
function sweepUnmapped() {
......@@ -198,9 +198,9 @@ Persistence.Automapping = class {
networkSourceCode[this._processingPromiseSymbol] = createBindingPromise;
/**
* @param {?Persistence.AutomappingStatus} status
* @return {!Promise<?Persistence.AutomappingStatus>}
* @this {Persistence.Automapping}
* @param {?AutomappingStatus} status
* @return {!Promise<?AutomappingStatus>}
* @this {Automapping}
*/
async function validateStatus(status) {
if (!status) {
......@@ -266,8 +266,8 @@ Persistence.Automapping = class {
}
/**
* @param {?Persistence.AutomappingStatus} status
* @this {Persistence.Automapping}
* @param {?AutomappingStatus} status
* @this {Automapping}
*/
function onStatus(status) {
if (networkSourceCode[this._processingPromiseSymbol] !== createBindingPromise) {
......@@ -298,7 +298,7 @@ Persistence.Automapping = class {
}
/**
* @param {!Persistence.AutomappingStatus} binding
* @param {!AutomappingStatus} binding
*/
_prevalidationFailedForTest(binding) {
}
......@@ -333,20 +333,19 @@ Persistence.Automapping = class {
/**
* @param {!Workspace.UISourceCode} networkSourceCode
* @return {!Promise<?Persistence.AutomappingStatus>}
* @return {!Promise<?AutomappingStatus>}
*/
_createBinding(networkSourceCode) {
if (networkSourceCode.url().startsWith('file://') || networkSourceCode.url().startsWith('snippet://')) {
const decodedUrl = decodeURI(networkSourceCode.url());
const fileSourceCode = this._fileSystemUISourceCodes.get(decodedUrl);
const status =
fileSourceCode ? new Persistence.AutomappingStatus(networkSourceCode, fileSourceCode, false) : null;
const status = fileSourceCode ? new AutomappingStatus(networkSourceCode, fileSourceCode, false) : null;
return Promise.resolve(status);
}
let networkPath = Common.ParsedURL.extractPath(networkSourceCode.url());
if (networkPath === null) {
return Promise.resolve(/** @type {?Persistence.AutomappingStatus} */ (null));
return Promise.resolve(/** @type {?AutomappingStatus} */ (null));
}
if (networkPath.endsWith('/')) {
......@@ -356,13 +355,13 @@ Persistence.Automapping = class {
const similarFiles =
this._filesIndex.similarFiles(urlDecodedNetworkPath).map(path => this._fileSystemUISourceCodes.get(path));
if (!similarFiles.length) {
return Promise.resolve(/** @type {?Persistence.AutomappingStatus} */ (null));
return Promise.resolve(/** @type {?AutomappingStatus} */ (null));
}
return this._pullMetadatas(similarFiles.concat(networkSourceCode)).then(onMetadatas.bind(this));
/**
* @this {Persistence.Automapping}
* @this {Automapping}
*/
function onMetadatas() {
const activeFiles = similarFiles.filter(file => !!this._activeFoldersIndex.closestParentFolder(file.url()));
......@@ -372,7 +371,7 @@ Persistence.Automapping = class {
if (activeFiles.length !== 1) {
return null;
}
return new Persistence.AutomappingStatus(networkSourceCode, activeFiles[0], false);
return new AutomappingStatus(networkSourceCode, activeFiles[0], false);
}
// Try to find exact matches, prioritizing active folders.
......@@ -383,7 +382,7 @@ Persistence.Automapping = class {
if (exactMatches.length !== 1) {
return null;
}
return new Persistence.AutomappingStatus(networkSourceCode, exactMatches[0], true);
return new AutomappingStatus(networkSourceCode, exactMatches[0], true);
}
}
......@@ -415,12 +414,12 @@ Persistence.Automapping = class {
return timeMatches && contentMatches;
});
}
};
}
/**
* @unrestricted
*/
Persistence.Automapping.FilePathIndex = class {
export class FilePathIndex {
/**
* @param {!Persistence.PathEncoder} encoder
*/
......@@ -458,12 +457,12 @@ Persistence.Automapping.FilePathIndex = class {
return this._reversedIndex.words(longestCommonPrefix)
.map(encodedPath => this._encoder.decode(encodedPath.reverse()));
}
};
}
/**
* @unrestricted
*/
Persistence.Automapping.FolderIndex = class {
export class FolderIndex {
/**
* @param {!Persistence.PathEncoder} encoder
*/
......@@ -520,12 +519,12 @@ Persistence.Automapping.FolderIndex = class {
const commonPrefix = this._index.longestPrefix(encodedPath, true);
return this._encoder.decode(commonPrefix);
}
};
}
/**
* @unrestricted
*/
Persistence.AutomappingStatus = class {
export class AutomappingStatus {
/**
* @param {!Workspace.UISourceCode} network
* @param {!Workspace.UISourceCode} fileSystem
......@@ -536,4 +535,22 @@ Persistence.AutomappingStatus = class {
this.fileSystem = fileSystem;
this.exactMatch = exactMatch;
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.Automapping = Automapping;
/** @constructor */
Persistence.Automapping.FilePathIndex = FilePathIndex;
/** @constructor */
Persistence.Automapping.FolderIndex = FolderIndex;
/** @constructor */
Persistence.AutomappingStatus = AutomappingStatus;
......@@ -31,7 +31,7 @@
* @implements {UI.ListWidget.Delegate}
* @unrestricted
*/
Persistence.EditFileSystemView = class extends UI.VBox {
export default class EditFileSystemView extends UI.VBox {
/**
* @param {string} fileSystemPath
*/
......@@ -166,7 +166,7 @@ Persistence.EditFileSystemView = class extends UI.VBox {
* @param {number} index
* @param {!HTMLInputElement|!HTMLSelectElement} input
* @return {!UI.ListWidget.ValidatorResult}
* @this {Persistence.EditFileSystemView}
* @this {EditFileSystemView}
*/
function pathPrefixValidator(item, index, input) {
const prefix = this._normalizePrefix(input.value.trim());
......@@ -196,4 +196,13 @@ Persistence.EditFileSystemView = class extends UI.VBox {
}
return prefix + (prefix[prefix.length - 1] === '/' ? '' : '/');
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.EditFileSystemView = EditFileSystemView;
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Persistence.FileSystemWorkspaceBinding = class {
export default class FileSystemWorkspaceBinding {
/**
* @param {!Persistence.IsolatedFileSystemManager} isolatedFileSystemManager
* @param {!Workspace.Workspace} workspace
......@@ -47,7 +47,7 @@ Persistence.FileSystemWorkspaceBinding = class {
this._isolatedFileSystemManager.addEventListener(
Persistence.IsolatedFileSystemManager.Events.FileSystemFilesChanged, this._fileSystemFilesChanged, this)
];
/** @type {!Map.<string, !Persistence.FileSystemWorkspaceBinding.FileSystem>} */
/** @type {!Map.<string, !FileSystem>} */
this._boundFileSystems = new Map();
this._isolatedFileSystemManager.waitForFileSystems().then(this._onFileSystemsLoaded.bind(this));
}
......@@ -66,7 +66,7 @@ Persistence.FileSystemWorkspaceBinding = class {
*/
static relativePath(uiSourceCode) {
const baseURL =
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (uiSourceCode.project())._fileSystemBaseURL;
/** @type {!FileSystem}*/ (uiSourceCode.project())._fileSystemBaseURL;
return uiSourceCode.url().substring(baseURL.length).split('/');
}
......@@ -76,7 +76,7 @@ Persistence.FileSystemWorkspaceBinding = class {
*/
static tooltipForUISourceCode(uiSourceCode) {
const fileSystem =
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (uiSourceCode.project())._fileSystem;
/** @type {!FileSystem}*/ (uiSourceCode.project())._fileSystem;
return fileSystem.tooltipForURL(uiSourceCode.url());
}
......@@ -86,7 +86,7 @@ Persistence.FileSystemWorkspaceBinding = class {
*/
static fileSystemType(project) {
const fileSystem =
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (project)._fileSystem;
/** @type {!FileSystem}*/ (project)._fileSystem;
return fileSystem.type();
}
......@@ -96,7 +96,7 @@ Persistence.FileSystemWorkspaceBinding = class {
*/
static fileSystemSupportsAutomapping(project) {
const fileSystem =
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (project)._fileSystem;
/** @type {!FileSystem}*/ (project)._fileSystem;
return fileSystem.supportsAutomapping();
}
......@@ -106,7 +106,7 @@ Persistence.FileSystemWorkspaceBinding = class {
* @return {string}
*/
static completeURL(project, relativePath) {
const fsProject = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (project);
const fsProject = /** @type {!FileSystem}*/ (project);
return fsProject._fileSystemBaseURL + relativePath;
}
......@@ -146,7 +146,7 @@ Persistence.FileSystemWorkspaceBinding = class {
* @param {!Persistence.PlatformFileSystem} fileSystem
*/
_addFileSystem(fileSystem) {
const boundFileSystem = new Persistence.FileSystemWorkspaceBinding.FileSystem(this, fileSystem, this._workspace);
const boundFileSystem = new FileSystem(this, fileSystem, this._workspace);
this._boundFileSystems.set(fileSystem.path(), boundFileSystem);
}
......@@ -197,21 +197,21 @@ Persistence.FileSystemWorkspaceBinding = class {
this._boundFileSystems.remove(fileSystem._fileSystem.path());
}
}
};
}
/**
* @implements {Workspace.Project}
* @unrestricted
*/
Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.ProjectStore {
export class FileSystem extends Workspace.ProjectStore {
/**
* @param {!Persistence.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
* @param {!FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
* @param {!Persistence.PlatformFileSystem} isolatedFileSystem
* @param {!Workspace.Workspace} workspace
*/
constructor(fileSystemWorkspaceBinding, isolatedFileSystem, workspace) {
const fileSystemPath = isolatedFileSystem.path();
const id = Persistence.FileSystemWorkspaceBinding.projectId(fileSystemPath);
const id = FileSystemWorkspaceBinding.projectId(fileSystemPath);
console.assert(!workspace.project(id));
const displayName = fileSystemPath.substr(fileSystemPath.lastIndexOf('/') + 1);
......@@ -274,12 +274,12 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
* @return {!Promise<?Workspace.UISourceCodeMetadata>}
*/
requestMetadata(uiSourceCode) {
if (uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata]) {
return uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata];
if (uiSourceCode[_metadata]) {
return uiSourceCode[_metadata];
}
const relativePath = this._filePathForUISourceCode(uiSourceCode);
const promise = this._fileSystem.getMetadata(relativePath).then(onMetadata);
uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata] = promise;
uiSourceCode[_metadata] = promise;
return promise;
/**
......@@ -339,7 +339,7 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
*/
fullDisplayName(uiSourceCode) {
const baseURL =
/** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (uiSourceCode.project())._fileSystemParentURL;
/** @type {!FileSystem}*/ (uiSourceCode.project())._fileSystemParentURL;
return uiSourceCode.url().substring(baseURL.length);
}
......@@ -369,7 +369,7 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
/**
* @param {boolean} success
* @param {string=} newName
* @this {Persistence.FileSystemWorkspaceBinding.FileSystem}
* @this {FileSystem}
*/
function innerCallback(success, newName) {
if (!success || !newName) {
......@@ -450,7 +450,7 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
/**
* @param {number} from
* @this {Persistence.FileSystemWorkspaceBinding.FileSystem}
* @this {FileSystem}
*/
function reportFileChunk(from) {
const to = Math.min(from + chunkSize, filePaths.length);
......@@ -569,7 +569,7 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
this.addUISourceCode(this.createUISourceCode(path, contentType));
return;
}
uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata] = null;
uiSourceCode[_metadata] = null;
uiSourceCode.checkContentUpdated();
}
......@@ -584,6 +584,20 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
dispose() {
this.removeProject();
}
};
}
Persistence.FileSystemWorkspaceBinding._metadata = Symbol('FileSystemWorkspaceBinding.Metadata');
export const _metadata = Symbol('FileSystemWorkspaceBinding.Metadata');
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.FileSystemWorkspaceBinding = FileSystemWorkspaceBinding;
/** @constructor */
Persistence.FileSystemWorkspaceBinding.FileSystem = FileSystem;
Persistence.FileSystemWorkspaceBinding._metadata = _metadata;
......@@ -30,7 +30,7 @@
/**
* @unrestricted
*/
Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
export default class IsolatedFileSystem extends Persistence.PlatformFileSystem {
/**
* @param {!Persistence.IsolatedFileSystemManager} manager
* @param {string} path
......@@ -64,18 +64,18 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
* @param {string} type
* @param {string} name
* @param {string} rootURL
* @return {!Promise<?Persistence.IsolatedFileSystem>}
* @return {!Promise<?IsolatedFileSystem>}
*/
static create(manager, path, embedderPath, type, name, rootURL) {
const domFileSystem = Host.InspectorFrontendHost.isolatedFileSystem(name, rootURL);
if (!domFileSystem) {
return Promise.resolve(/** @type {?Persistence.IsolatedFileSystem} */ (null));
return Promise.resolve(/** @type {?IsolatedFileSystem} */ (null));
}
const fileSystem = new Persistence.IsolatedFileSystem(manager, path, embedderPath, domFileSystem, type);
const fileSystem = new IsolatedFileSystem(manager, path, embedderPath, domFileSystem, type);
return fileSystem._initializeFilePaths()
.then(() => fileSystem)
.catchException(/** @type {?Persistence.IsolatedFileSystem} */ (null));
.catchException(/** @type {?IsolatedFileSystem} */ (null));
}
/**
......@@ -120,7 +120,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
* @param {!FileError} error
*/
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when getting file metadata \'' + path);
fulfill(null);
}
......@@ -163,7 +163,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!Array.<!FileEntry>} entries
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function innerCallback(entries) {
for (let i = 0; i < entries.length; ++i) {
......@@ -224,7 +224,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
_innerCreateFolderIfNeeded(path) {
return new Promise(resolve => {
this._domFileSystem.root.getDirectory(path, {create: true}, dirEntry => resolve(dirEntry), error => {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' trying to create directory \'' + path + '\'');
resolve(null);
});
......@@ -252,7 +252,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
* @param {string} name
* @param {number=} newFileIndex
* @return {!Promise<?FileEntry>}
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function createFileCandidate(name, newFileIndex) {
return new Promise(resolve => {
......@@ -262,7 +262,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
resolve(createFileCandidate.call(this, name, (newFileIndex ? newFileIndex + 1 : 1)));
return;
}
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(
errorMessage + ' when testing if file exists \'' + (this.path() + '/' + path + '/' + nameCandidate) +
'\'');
......@@ -285,7 +285,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!FileEntry} fileEntry
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function fileEntryLoaded(fileEntry) {
fileEntry.remove(fileEntryRemoved, errorHandler.bind(this));
......@@ -297,12 +297,12 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!FileError} error
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
* @suppress {checkTypes}
* TODO(jsbell): Update externs replacing FileError with DOMException. https://crbug.com/496901
*/
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when deleting file \'' + (this.path() + '/' + path) + '\'');
resolveCallback(false);
}
......@@ -320,7 +320,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
}, errorHandler.bind(this));
/**
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function errorHandler(error) {
if (error.name === 'NotFoundError') {
......@@ -328,7 +328,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
return;
}
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when getting content for file \'' + (this.path() + '/' + path) + '\'');
resolve(null);
}
......@@ -350,7 +350,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
const reader = new FileReader();
const extension = Common.ParsedURL.extractExtension(path);
const encoded = Persistence.IsolatedFileSystem.BinaryExtensions.has(extension);
const encoded = BinaryExtensions.has(extension);
const readPromise = new Promise(x => reader.onloadend = x);
if (encoded) {
reader.readAsBinaryString(blob);
......@@ -399,7 +399,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!FileEntry} entry
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function fileEntryLoaded(entry) {
entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this));
......@@ -407,7 +407,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!FileWriter} fileWriter
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
async function fileWriterCreated(fileWriter) {
fileWriter.onerror = errorHandler.bind(this);
......@@ -427,10 +427,10 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
}
/**
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when setting content for file \'' + (this.path() + '/' + path) + '\'');
callback();
}
......@@ -455,7 +455,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!FileEntry} entry
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function fileEntryLoaded(entry) {
if (entry.name === newName) {
......@@ -469,7 +469,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!Entry} entry
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function dirEntryLoaded(entry) {
dirEntry = entry;
......@@ -484,7 +484,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
}
/**
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function newFileEntryLoadErrorHandler(error) {
if (error.name !== 'NotFoundError') {
......@@ -502,10 +502,10 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
}
/**
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when renaming file \'' + (this.path() + '/' + path) + '\' to \'' + newName + '\'');
callback(false);
}
......@@ -535,7 +535,7 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
dirReader.readEntries(innerCallback, errorHandler);
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when reading directory \'' + dirEntry.fullPath + '\'');
callback([]);
}
......@@ -550,14 +550,14 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
/**
* @param {!DirectoryEntry} dirEntry
* @this {Persistence.IsolatedFileSystem}
* @this {IsolatedFileSystem}
*/
function innerCallback(dirEntry) {
this._readDirectory(dirEntry, callback);
}
function errorHandler(error) {
const errorMessage = Persistence.IsolatedFileSystem.errorMessage(error);
const errorMessage = IsolatedFileSystem.errorMessage(error);
console.error(errorMessage + ' when requesting entry \'' + path + '\'');
callback([]);
}
......@@ -675,20 +675,19 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
*/
contentType(path) {
const extension = Common.ParsedURL.extractExtension(path);
if (Persistence.IsolatedFileSystem._styleSheetExtensions.has(extension)) {
if (_styleSheetExtensions.has(extension)) {
return Common.resourceTypes.Stylesheet;
}
if (Persistence.IsolatedFileSystem._documentExtensions.has(extension)) {
if (_documentExtensions.has(extension)) {
return Common.resourceTypes.Document;
}
if (Persistence.IsolatedFileSystem.ImageExtensions.has(extension)) {
if (ImageExtensions.has(extension)) {
return Common.resourceTypes.Image;
}
if (Persistence.IsolatedFileSystem._scriptExtensions.has(extension)) {
if (_scriptExtensions.has(extension)) {
return Common.resourceTypes.Script;
}
return Persistence.IsolatedFileSystem.BinaryExtensions.has(extension) ? Common.resourceTypes.Other :
Common.resourceTypes.Document;
return BinaryExtensions.has(extension) ? Common.resourceTypes.Other : Common.resourceTypes.Document;
}
/**
......@@ -708,19 +707,19 @@ Persistence.IsolatedFileSystem = class extends Persistence.PlatformFileSystem {
supportsAutomapping() {
return this.type() !== 'overrides';
}
};
}
Persistence.IsolatedFileSystem._styleSheetExtensions = new Set(['css', 'scss', 'sass', 'less']);
Persistence.IsolatedFileSystem._documentExtensions = new Set(['htm', 'html', 'asp', 'aspx', 'phtml', 'jsp']);
Persistence.IsolatedFileSystem._scriptExtensions = new Set([
export const _styleSheetExtensions = new Set(['css', 'scss', 'sass', 'less']);
export const _documentExtensions = new Set(['htm', 'html', 'asp', 'aspx', 'phtml', 'jsp']);
export const _scriptExtensions = new Set([
'asp', 'aspx', 'c', 'cc', 'cljs', 'coffee', 'cpp', 'cs', 'dart', 'java', 'js',
'jsp', 'jsx', 'h', 'm', 'mjs', 'mm', 'py', 'sh', 'ts', 'tsx', 'ls'
]);
Persistence.IsolatedFileSystem.ImageExtensions =
new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', 'bmp']);
export const ImageExtensions = new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', 'bmp']);
Persistence.IsolatedFileSystem.BinaryExtensions = new Set([
export const BinaryExtensions = new Set([
// Executable extensions, roughly taken from https://en.wikipedia.org/wiki/Comparison_of_executable_file_formats
'cmd', 'com', 'exe',
// Archive extensions, roughly taken from https://en.wikipedia.org/wiki/List_of_archive_formats
......@@ -732,3 +731,18 @@ Persistence.IsolatedFileSystem.BinaryExtensions = new Set([
// Image file extensions
'jpeg', 'jpg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', 'bmp'
]);
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.IsolatedFileSystem = IsolatedFileSystem;
Persistence.IsolatedFileSystem._styleSheetExtensions = _styleSheetExtensions;
Persistence.IsolatedFileSystem._documentExtensions = _documentExtensions;
Persistence.IsolatedFileSystem._scriptExtensions = _scriptExtensions;
Persistence.IsolatedFileSystem.ImageExtensions = ImageExtensions;
Persistence.IsolatedFileSystem.BinaryExtensions = BinaryExtensions;
......@@ -31,7 +31,7 @@
/**
* @unrestricted
*/
Persistence.IsolatedFileSystemManager = class extends Common.Object {
export default class IsolatedFileSystemManager extends Common.Object {
constructor() {
super();
......@@ -77,7 +77,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
/**
* @param {!Common.Event} event
* @this {Persistence.IsolatedFileSystemManager}
* @this {IsolatedFileSystemManager}
*/
function onFileSystemsLoaded(event) {
const fileSystems = /** @type {!Array.<!Persistence.IsolatedFileSystemManager.FileSystem>} */ (event.data);
......@@ -135,7 +135,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
/**
* @param {?Persistence.PlatformFileSystem} fileSystem
* @this {Persistence.IsolatedFileSystemManager}
* @this {IsolatedFileSystemManager}
*/
function storeFileSystem(fileSystem) {
if (!fileSystem) {
......@@ -143,7 +143,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
}
this._fileSystems.set(fileSystemURL, fileSystem);
if (dispatchEvent) {
this.dispatchEventToListeners(Persistence.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem);
this.dispatchEventToListeners(Events.FileSystemAdded, fileSystem);
}
return fileSystem;
}
......@@ -155,7 +155,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
*/
addPlatformFileSystem(fileSystemURL, fileSystem) {
this._fileSystems.set(fileSystemURL, fileSystem);
this.dispatchEventToListeners(Persistence.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem);
this.dispatchEventToListeners(Events.FileSystemAdded, fileSystem);
}
/**
......@@ -192,7 +192,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
}
this._fileSystems.delete(fileSystemPath);
isolatedFileSystem.fileSystemRemoved();
this.dispatchEventToListeners(Persistence.IsolatedFileSystemManager.Events.FileSystemRemoved, isolatedFileSystem);
this.dispatchEventToListeners(Events.FileSystemRemoved, isolatedFileSystem);
}
/**
......@@ -205,12 +205,12 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
removed: groupFilePathsIntoFileSystemPaths.call(this, event.data.removed)
};
this.dispatchEventToListeners(Persistence.IsolatedFileSystemManager.Events.FileSystemFilesChanged, urlPaths);
this.dispatchEventToListeners(Events.FileSystemFilesChanged, urlPaths);
/**
* @param {!Array<string>} embedderPaths
* @return {!Platform.Multimap<string, string>}
* @this {Persistence.IsolatedFileSystemManager}
* @this {IsolatedFileSystemManager}
*/
function groupFilePathsIntoFileSystemPaths(embedderPaths) {
const paths = new Platform.Multimap();
......@@ -282,7 +282,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
* @return {number}
*/
registerCallback(callback) {
const requestId = ++Persistence.IsolatedFileSystemManager._lastRequestId;
const requestId = ++_lastRequestId;
this._callbacks.set(requestId, callback);
return requestId;
}
......@@ -292,7 +292,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
* @return {number}
*/
registerProgress(progress) {
const requestId = ++Persistence.IsolatedFileSystemManager._lastRequestId;
const requestId = ++_lastRequestId;
this._progresses.set(requestId, progress);
return requestId;
}
......@@ -357,16 +357,10 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
callback.call(null, files);
this._callbacks.delete(requestId);
}
};
/** @typedef {!{type: string, fileSystemName: string, rootURL: string, fileSystemPath: string}} */
Persistence.IsolatedFileSystemManager.FileSystem;
/** @typedef {!{changed:!Platform.Multimap<string, string>, added:!Platform.Multimap<string, string>, removed:!Platform.Multimap<string, string>}} */
Persistence.IsolatedFileSystemManager.FilesChangedData;
}
/** @enum {symbol} */
Persistence.IsolatedFileSystemManager.Events = {
export const Events = {
FileSystemAdded: Symbol('FileSystemAdded'),
FileSystemRemoved: Symbol('FileSystemRemoved'),
FileSystemFilesChanged: Symbol('FileSystemFilesChanged'),
......@@ -374,9 +368,28 @@ Persistence.IsolatedFileSystemManager.Events = {
ExcludedFolderRemoved: Symbol('ExcludedFolderRemoved')
};
Persistence.IsolatedFileSystemManager._lastRequestId = 0;
export let _lastRequestId = 0;
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.IsolatedFileSystemManager = IsolatedFileSystemManager;
/** @enum {symbol} */
Persistence.IsolatedFileSystemManager.Events = Events;
Persistence.IsolatedFileSystemManager._lastRequestId = _lastRequestId;
/** @typedef {!{type: string, fileSystemName: string, rootURL: string, fileSystemPath: string}} */
Persistence.IsolatedFileSystemManager.FileSystem;
/** @typedef {!{changed:!Platform.Multimap<string, string>, added:!Platform.Multimap<string, string>, removed:!Platform.Multimap<string, string>}} */
Persistence.IsolatedFileSystemManager.FilesChangedData;
/**
* @type {!Persistence.IsolatedFileSystemManager}
* @type {!IsolatedFileSystemManager}
*/
Persistence.isolatedFileSystemManager;
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.NetworkPersistenceManager = class extends Common.Object {
export default class NetworkPersistenceManager extends Common.Object {
/**
* @param {!Workspace.Workspace} workspace
*/
......@@ -162,7 +162,7 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
// encodeURI() escapes all the unsafe filename characters except /:?*
let encodedName = encodeURI(pathPart).replace(/[\/:\?\*]/g, match => '%' + match[0].charCodeAt(0).toString(16));
// Windows does not allow a small set of filenames.
if (Persistence.NetworkPersistenceManager._reservedFileNames.has(encodedName.toLowerCase())) {
if (_reservedFileNames.has(encodedName.toLowerCase())) {
encodedName = encodedName.split('').map(char => '%' + char.charCodeAt(0).toString(16)).join('');
}
// Windows does not allow the file to end in a space or dot (space should already be encoded).
......@@ -353,7 +353,7 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
this._updateInterceptionThrottler.schedule(innerUpdateInterceptionPatterns.bind(this));
/**
* @this {Persistence.NetworkPersistenceManager}
* @this {NetworkPersistenceManager}
* @return {!Promise}
*/
function innerUpdateInterceptionPatterns() {
......@@ -425,7 +425,7 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
}
this._updateActiveProject();
this.dispatchEventToListeners(Persistence.NetworkPersistenceManager.Events.ProjectChanged, this._project);
this.dispatchEventToListeners(Events.ProjectChanged, this._project);
}
/**
......@@ -500,16 +500,28 @@ Persistence.NetworkPersistenceManager = class extends Common.Object {
const blob = await project.requestFileBlob(fileSystemUISourceCode);
interceptedRequest.continueRequestWithContent(new Blob([blob], {type: mimeType}));
}
};
}
Persistence.NetworkPersistenceManager._reservedFileNames = new Set([
export const _reservedFileNames = new Set([
'con', 'prn', 'aux', 'nul', 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7',
'com8', 'com9', 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'
]);
Persistence.NetworkPersistenceManager.Events = {
export const Events = {
ProjectChanged: Symbol('ProjectChanged')
};
/** @type {!Persistence.NetworkPersistenceManager} */
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.NetworkPersistenceManager = NetworkPersistenceManager;
Persistence.NetworkPersistenceManager._reservedFileNames = _reservedFileNames;
Persistence.NetworkPersistenceManager.Events = Events;
/** @type {!NetworkPersistenceManager} */
Persistence.networkPersistenceManager;
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.PersistenceActions = {};
/**
* @implements {UI.ContextMenu.Provider}
* @unrestricted
*/
Persistence.PersistenceActions.ContextMenuProvider = class {
export class ContextMenuProvider {
/**
* @override
* @param {!Event} event
......@@ -53,4 +51,15 @@ Persistence.PersistenceActions.ContextMenuProvider = class {
Common.UIString('Open in containing folder'), () => Host.InspectorFrontendHost.showItemInFolder(path));
}
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
Persistence.PersistenceActions = {};
/** @constructor */
Persistence.PersistenceActions.ContextMenuProvider = ContextMenuProvider;
......@@ -5,7 +5,7 @@
/**
* @unrestricted
*/
Persistence.Persistence = class extends Common.Object {
export default class PersistenceImpl extends Common.Object {
/**
* @param {!Workspace.Workspace} workspace
* @param {!Bindings.BreakpointManager} breakpointManager
......@@ -39,39 +39,39 @@ Persistence.Persistence = class extends Common.Object {
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
addBinding(binding) {
this._innerAddBinding(binding);
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
addBindingForTest(binding) {
this._innerAddBinding(binding);
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
removeBinding(binding) {
this._innerRemoveBinding(binding);
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
removeBindingForTest(binding) {
this._innerRemoveBinding(binding);
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
_innerAddBinding(binding) {
binding.network[Persistence.Persistence._binding] = binding;
binding.fileSystem[Persistence.Persistence._binding] = binding;
binding.network[_binding] = binding;
binding.fileSystem[_binding] = binding;
binding.fileSystem.forceLoadOnCheckContent();
......@@ -100,22 +100,22 @@ Persistence.Persistence = class extends Common.Object {
this._notifyBindingEvent(binding.network);
this._notifyBindingEvent(binding.fileSystem);
this.dispatchEventToListeners(Persistence.Persistence.Events.BindingCreated, binding);
this.dispatchEventToListeners(Events.BindingCreated, binding);
}
/**
* @param {!Persistence.PersistenceBinding} binding
* @param {!PersistenceBinding} binding
*/
_innerRemoveBinding(binding) {
if (binding.network[Persistence.Persistence._binding] !== binding) {
if (binding.network[_binding] !== binding) {
return;
}
console.assert(
binding.network[Persistence.Persistence._binding] === binding.fileSystem[Persistence.Persistence._binding],
binding.network[_binding] === binding.fileSystem[_binding],
'ERROR: inconsistent binding for networkURL ' + binding.network.url());
binding.network[Persistence.Persistence._binding] = null;
binding.fileSystem[Persistence.Persistence._binding] = null;
binding.network[_binding] = null;
binding.fileSystem[_binding] = null;
binding.network.removeEventListener(
Workspace.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
......@@ -131,15 +131,15 @@ Persistence.Persistence = class extends Common.Object {
this._notifyBindingEvent(binding.network);
this._notifyBindingEvent(binding.fileSystem);
this.dispatchEventToListeners(Persistence.Persistence.Events.BindingRemoved, binding);
this.dispatchEventToListeners(Events.BindingRemoved, binding);
}
/**
* @param {!Persistence.AutomappingStatus} status
*/
_onStatusAdded(status) {
const binding = new Persistence.PersistenceBinding(status.network, status.fileSystem);
status[Persistence.Persistence._binding] = binding;
const binding = new PersistenceBinding(status.network, status.fileSystem);
status[_binding] = binding;
this._innerAddBinding(binding);
}
......@@ -147,7 +147,7 @@ Persistence.Persistence = class extends Common.Object {
* @param {!Persistence.AutomappingStatus} status
*/
_onStatusRemoved(status) {
const binding = /** @type {!Persistence.PersistenceBinding} */ (status[Persistence.Persistence._binding]);
const binding = /** @type {!PersistenceBinding} */ (status[_binding]);
this._innerRemoveBinding(binding);
}
......@@ -163,15 +163,15 @@ Persistence.Persistence = class extends Common.Object {
* @param {!Workspace.UISourceCode} uiSourceCode
*/
_syncWorkingCopy(uiSourceCode) {
const binding = uiSourceCode[Persistence.Persistence._binding];
if (!binding || binding[Persistence.Persistence._muteWorkingCopy]) {
const binding = uiSourceCode[_binding];
if (!binding || binding[_muteWorkingCopy]) {
return;
}
const other = binding.network === uiSourceCode ? binding.fileSystem : binding.network;
if (!uiSourceCode.isDirty()) {
binding[Persistence.Persistence._muteWorkingCopy] = true;
binding[_muteWorkingCopy] = true;
other.resetWorkingCopy();
binding[Persistence.Persistence._muteWorkingCopy] = false;
binding[_muteWorkingCopy] = false;
this._contentSyncedForTest();
return;
}
......@@ -180,7 +180,7 @@ Persistence.Persistence = class extends Common.Object {
if (target.type() === SDK.Target.Type.Node) {
const newContent = uiSourceCode.workingCopy();
other.requestContent().then(() => {
const nodeJSContent = Persistence.Persistence.rewrapNodeJSContent(other, other.workingCopy(), newContent);
const nodeJSContent = PersistenceImpl.rewrapNodeJSContent(other, other.workingCopy(), newContent);
setWorkingCopy.call(this, () => nodeJSContent);
});
return;
......@@ -190,12 +190,12 @@ Persistence.Persistence = class extends Common.Object {
/**
* @param {function():string} workingCopyGetter
* @this {Persistence.Persistence}
* @this {PersistenceImpl}
*/
function setWorkingCopy(workingCopyGetter) {
binding[Persistence.Persistence._muteWorkingCopy] = true;
binding[_muteWorkingCopy] = true;
other.setWorkingCopyGetter(workingCopyGetter);
binding[Persistence.Persistence._muteWorkingCopy] = false;
binding[_muteWorkingCopy] = false;
this._contentSyncedForTest();
}
}
......@@ -215,15 +215,15 @@ Persistence.Persistence = class extends Common.Object {
* @param {boolean} encoded
*/
syncContent(uiSourceCode, newContent, encoded) {
const binding = uiSourceCode[Persistence.Persistence._binding];
if (!binding || binding[Persistence.Persistence._muteCommit]) {
const binding = uiSourceCode[_binding];
if (!binding || binding[_muteCommit]) {
return;
}
const other = binding.network === uiSourceCode ? binding.fileSystem : binding.network;
const target = Bindings.NetworkProject.targetForUISourceCode(binding.network);
if (target.type() === SDK.Target.Type.Node) {
other.requestContent().then(currentContent => {
const nodeJSContent = Persistence.Persistence.rewrapNodeJSContent(other, currentContent, newContent);
const nodeJSContent = PersistenceImpl.rewrapNodeJSContent(other, currentContent, newContent);
setContent.call(this, nodeJSContent);
});
return;
......@@ -232,12 +232,12 @@ Persistence.Persistence = class extends Common.Object {
/**
* @param {string} newContent
* @this {Persistence.Persistence}
* @this {PersistenceImpl}
*/
function setContent(newContent) {
binding[Persistence.Persistence._muteCommit] = true;
binding[_muteCommit] = true;
other.setContent(newContent, encoded);
binding[Persistence.Persistence._muteCommit] = false;
binding[_muteCommit] = false;
this._contentSyncedForTest();
}
}
......@@ -250,21 +250,18 @@ Persistence.Persistence = class extends Common.Object {
*/
static rewrapNodeJSContent(uiSourceCode, currentContent, newContent) {
if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) {
if (newContent.startsWith(Persistence.Persistence._NodePrefix) &&
newContent.endsWith(Persistence.Persistence._NodeSuffix)) {
newContent = newContent.substring(
Persistence.Persistence._NodePrefix.length, newContent.length - Persistence.Persistence._NodeSuffix.length);
if (newContent.startsWith(_NodePrefix) && newContent.endsWith(_NodeSuffix)) {
newContent = newContent.substring(_NodePrefix.length, newContent.length - _NodeSuffix.length);
}
if (currentContent.startsWith(Persistence.Persistence._NodeShebang)) {
newContent = Persistence.Persistence._NodeShebang + newContent;
if (currentContent.startsWith(_NodeShebang)) {
newContent = _NodeShebang + newContent;
}
} else {
if (newContent.startsWith(Persistence.Persistence._NodeShebang)) {
newContent = newContent.substring(Persistence.Persistence._NodeShebang.length);
if (newContent.startsWith(_NodeShebang)) {
newContent = newContent.substring(_NodeShebang.length);
}
if (currentContent.startsWith(Persistence.Persistence._NodePrefix) &&
currentContent.endsWith(Persistence.Persistence._NodeSuffix)) {
newContent = Persistence.Persistence._NodePrefix + newContent + Persistence.Persistence._NodeSuffix;
if (currentContent.startsWith(_NodePrefix) && currentContent.endsWith(_NodeSuffix)) {
newContent = _NodePrefix + newContent + _NodeSuffix;
}
}
return newContent;
......@@ -298,7 +295,7 @@ Persistence.Persistence = class extends Common.Object {
if (uiSourceCode.project().canSetFileContent()) {
return false;
}
if (uiSourceCode[Persistence.Persistence._binding]) {
if (uiSourceCode[_binding]) {
return false;
}
return !!uiSourceCode.hasCommits();
......@@ -306,10 +303,10 @@ Persistence.Persistence = class extends Common.Object {
/**
* @param {!Workspace.UISourceCode} uiSourceCode
* @return {?Persistence.PersistenceBinding}
* @return {?PersistenceBinding}
*/
binding(uiSourceCode) {
return uiSourceCode[Persistence.Persistence._binding] || null;
return uiSourceCode[_binding] || null;
}
/**
......@@ -397,17 +394,16 @@ Persistence.Persistence = class extends Common.Object {
}
return this._filePathPrefixesToBindingCount.has(filePath);
}
};
Persistence.Persistence._binding = Symbol('Persistence.Binding');
Persistence.Persistence._muteCommit = Symbol('Persistence.MuteCommit');
Persistence.Persistence._muteWorkingCopy = Symbol('Persistence.MuteWorkingCopy');
}
Persistence.Persistence._NodePrefix = '(function (exports, require, module, __filename, __dirname) { ';
Persistence.Persistence._NodeSuffix = '\n});';
Persistence.Persistence._NodeShebang = '#!/usr/bin/env node';
export const _binding = Symbol('Persistence.Binding');
export const _muteCommit = Symbol('Persistence.MuteCommit');
export const _muteWorkingCopy = Symbol('Persistence.MuteWorkingCopy');
export const _NodePrefix = '(function (exports, require, module, __filename, __dirname) { ';
export const _NodeSuffix = '\n});';
export const _NodeShebang = '#!/usr/bin/env node';
Persistence.Persistence.Events = {
export const Events = {
BindingCreated: Symbol('BindingCreated'),
BindingRemoved: Symbol('BindingRemoved')
};
......@@ -415,7 +411,7 @@ Persistence.Persistence.Events = {
/**
* @unrestricted
*/
Persistence.PathEncoder = class {
export class PathEncoder {
constructor() {
/** @type {!Common.CharacterIdMap<string>} */
this._encoder = new Common.CharacterIdMap();
......@@ -436,12 +432,12 @@ Persistence.PathEncoder = class {
decode(path) {
return path.split('').map(token => this._encoder.fromChar(token)).join('/');
}
};
}
/**
* @unrestricted
*/
Persistence.PersistenceBinding = class {
export class PersistenceBinding {
/**
* @param {!Workspace.UISourceCode} network
* @param {!Workspace.UISourceCode} fileSystem
......@@ -450,7 +446,30 @@ Persistence.PersistenceBinding = class {
this.network = network;
this.fileSystem = fileSystem;
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.Persistence = PersistenceImpl;
Persistence.Persistence._binding = _binding;
Persistence.Persistence._muteCommit = _muteCommit;
Persistence.Persistence._muteWorkingCopy = _muteWorkingCopy;
Persistence.Persistence._NodePrefix = _NodePrefix;
Persistence.Persistence._NodeSuffix = _NodeSuffix;
Persistence.Persistence._NodeShebang = _NodeShebang;
Persistence.Persistence.Events = Events;
/** @constructor */
Persistence.PathEncoder = PathEncoder;
/** @constructor */
Persistence.PersistenceBinding = PersistenceBinding;
/** @type {!Persistence.Persistence} */
/** @type {!PersistenceImpl} */
Persistence.persistence;
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.PersistenceUtils = class {
export default class PersistenceUtils {
/**
* @param {!Workspace.UISourceCode} uiSourceCode
* @return {string}
......@@ -32,7 +32,7 @@ Persistence.PersistenceUtils = class {
return null;
}
const icon = UI.Icon.create('mediumicon-file-sync');
icon.title = Persistence.PersistenceUtils.tooltipForUISourceCode(binding.network);
icon.title = PersistenceUtils.tooltipForUISourceCode(binding.network);
// TODO(allada) This will not work properly with dark theme.
if (Persistence.networkPersistenceManager.project() === binding.fileSystem.project()) {
icon.style.filter = 'hue-rotate(160deg)';
......@@ -45,16 +45,16 @@ Persistence.PersistenceUtils = class {
}
const icon = UI.Icon.create('mediumicon-file');
icon.title = Persistence.PersistenceUtils.tooltipForUISourceCode(uiSourceCode);
icon.title = PersistenceUtils.tooltipForUISourceCode(uiSourceCode);
return icon;
}
};
}
/**
* @extends {Common.Object}
* @implements {Components.LinkDecorator}
*/
Persistence.PersistenceUtils.LinkDecorator = class extends Common.Object {
export class LinkDecorator extends Common.Object {
/**
* @param {!Persistence.Persistence} persistence
*/
......@@ -78,6 +78,18 @@ Persistence.PersistenceUtils.LinkDecorator = class extends Common.Object {
* @return {?UI.Icon}
*/
linkIcon(uiSourceCode) {
return Persistence.PersistenceUtils.iconForUISourceCode(uiSourceCode);
return PersistenceUtils.iconForUISourceCode(uiSourceCode);
}
};
\ No newline at end of file
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.PersistenceUtils = PersistenceUtils;
/** @constructor */
Persistence.PersistenceUtils.LinkDecorator = LinkDecorator;
\ No newline at end of file
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.PlatformFileSystem = class {
export default class PlatformFileSystem {
/**
* @param {string} path
* @param {string} type
......@@ -191,4 +191,13 @@ Persistence.PlatformFileSystem = class {
supportsAutomapping() {
throw new Error('Not implemented');
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.PlatformFileSystem = PlatformFileSystem;
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Persistence.WorkspaceSettingsTab = class extends UI.VBox {
export default class WorkspaceSettingsTab extends UI.VBox {
constructor() {
super();
this.registerRequiredCSS('persistence/workspaceSettingsTab.css');
......@@ -166,4 +166,13 @@ Persistence.WorkspaceSettingsTab = class extends UI.VBox {
element.remove();
}
}
};
}
/* Legacy exported object */
self.Persistence = self.Persistence || {};
/* Legacy exported object */
Persistence = Persistence || {};
/** @constructor */
Persistence.WorkspaceSettingsTab = WorkspaceSettingsTab;
......@@ -43,14 +43,16 @@
"className": "Persistence.PersistenceActions.ContextMenuProvider"
}
],
"scripts": [
"scripts": [],
"modules": [
"persistence.js",
"PlatformFileSystem.js",
"IsolatedFileSystem.js",
"IsolatedFileSystemManager.js",
"FileSystemWorkspaceBinding.js",
"Automapping.js",
"NetworkPersistenceManager.js",
"Persistence.js",
"PersistenceImpl.js",
"PersistenceActions.js",
"PersistenceUtils.js",
"EditFileSystemView.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 './PlatformFileSystem.js';
import * as Automapping from './Automapping.js';
import * as EditFileSystemView from './EditFileSystemView.js';
import * as FileSystemWorkspaceBinding from './FileSystemWorkspaceBinding.js';
import * as IsolatedFileSystem from './IsolatedFileSystem.js';
import * as IsolatedFileSystemManager from './IsolatedFileSystemManager.js';
import * as NetworkPersistenceManager from './NetworkPersistenceManager.js';
import * as PersistenceActions from './PersistenceActions.js';
import * as Persistence from './PersistenceImpl.js';
import * as PersistenceUtils from './PersistenceUtils.js';
import * as PlatformFileSystem from './PlatformFileSystem.js';
import * as WorkspaceSettingsTab from './WorkspaceSettingsTab.js';
export {
Automapping,
EditFileSystemView,
FileSystemWorkspaceBinding,
IsolatedFileSystem,
IsolatedFileSystemManager,
NetworkPersistenceManager,
Persistence,
PersistenceActions,
PersistenceUtils,
PlatformFileSystem,
WorkspaceSettingsTab,
};
......@@ -15,3 +15,4 @@ import './services/services.js';
import './workspace/workspace.js';
import './bindings/bindings.js';
import './components/components.js';
import './persistence/persistence.js';
\ No newline at end of file
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