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