Skip to content

Release notes

Alf Nielsen edited this page Nov 21, 2019 · 46 revisions

0.9.7

Add new vscode methods:

0.9.3

Added

Add new raw methods:

Add new ts methods:

Add new area: webview

New webview methods added:

0.9.2

Added

Add two raw methods:

0.9.1

Fix

Fix problem with removing new line feed when add importName to existing import in tsInsertImport

Changes

tsInsertVariableObjectProperty's params are now optional, so that it can add a key without value:

EX:

//from
const f = {
   f: f
}
//to
const f = {
   f
}

0.9

Added

New ts match method: tsMatchVariableList

This match method find an declaration

ex: const foo = 1

ex: const foo = 1, foo2 = 2

While tsMatchVariable only finds 'foo = 1' part

Also added tsIsVariableList

New ts top level transform methods added:

tsInsertVariableObjectProperty

It will add a key-value pair to a variable thats in ObjectExpression, if the key don't exist

tsInsertInterfaceMember

It will add a member to an interface if the member don't exist

tsInsertEnumMember

It will add a member to an enum instance if the member don't exist

Breaking changes + fix

tsInsertImport has now 'options' params instead of direct params 'isDefault' and 'useDoubleQuotation' which are now both part of the options params.

EX

Before: vsc.tsInsertImport(source1, 't', './t.ts', true, true)

Now: vsc.tsInsertImport(source1, 't', './t.ts', { isDefault: true, useDoubleQuotation: true })

tsInsertImport has also been fix so it don't duplicate importNames like import { t, t } form './x.ts' when you insert 't'

Internal

New area typescript-top-level-transform has been added. For now all method here are insert methods, that accept a source and return a transformed source. Method in this area are:

0.8.31

Fixes

Fix system method 'move'

Added

getLineStreamReader has now optional params 'excludeNewLine' (default value false). If set to true it will omit the newline feed from the returned lines.

Examples

All examples has been updated so they will be show with syntax highlight in vsc autocomplete dropdown.

Internal: Unit tests

There are now added test for: raw, system and typescript-base Test for the rest of vcs method will be added in the following updates (Missing tests: typescript-match, typescript-module-load, typescript-transform, vscode and vscTemplate)

0.8.30

Fix

Fix tsImportModule error on windows. (Fix incorrect change of import url!)

0.8.28 + 0.8.29

Add

Add tsInsertImport

Fix (Small breaking change)

Fix path match in tsMatchImport. Typescripts 'moduleSpecifier' (the path), returns the path including th e Quotation marks (' or "), which meant that the match path needed to include them.

Now they are remove before the match. (If you script included them, you need to remove them from your match)

Internal changes

The compiler script for vsc-base is updated, and it ready to be the base for creating more consisting test for all

0.8.27

Add

Add tsGetLocalModules

tsGetLocalModules has been added to tsLoadModule, and enables it to load imports with in the loaded modules.

In this implementation it don't checks for circular imports, which will create infinity loops, (So its recommended to only use local imports that you know don't have other imports)

This is the first version of handling imports, and the check for circular imports will most likely, be implemented in a future version.

tsGetLocalModules has been added primarily to make vsc-script's better.

0.8.26

Fix

made 'hasParent' option in tsIsValue and tsMatchValueNode

0.8.25

Add

Add tsIsImport and tsMatchImport

Change

Fix generic problems with callback (Callback now accept undefined) in tsFindNodePositionFromContent and tsFindAllNodePositionsFromContent

0.8.24

Add

0.8.23

Breaking changes

Fix problems with tsFindNodePositionFromContent and tsFindAllNodePositionsFromContent

The callback has change from returning a boolean to now returning a node.

Is this done to enable correct generic for the return node.

Use vsc 'match' function instead of 'is' function in the callback.

Add

tsMatchNode and tsMatchValueNode,

They are the same has tsIsNode and tsIsValue, but they return a ts.Node.

0.8.22

Add

Add generic to tsFindNodePositionFromContent and tsFindAllNodePositionsFromContent

This is to avoid having to cast node after finding it.

(vscode / typescript can't see that you kind of node you found)

0.8.21

fix

Fix ToTitleCase

0.8.20

Add

All 'tsIs' and 'tsMatch' methods that already has the optional options: 'hasAncestor', now also has the option: 'hasParent'

new method:

0.8.19

Breaking changes

VscodePosition (result from createVscodeRangeAndPosition and tsFindPositionFromContent ect.) now has fullContent, orgStart and orgEnd.

It will now remove comments as well as spaces. (The orgStart, orgEnd and fullContent has the contains the position and content without removing spaces and comments)

createVscodeRangeAndPosition optional params trimSpaces is now trimSpacesAndComments.

0.8.18

Breaking changes

insertAtRange and all method using it is now NOT async:

The underlying vscode commands has been changed to vscode.TextEdit, insert of snippets.

One major reason for this, is the scrolling behavior of the active document.

With snippets it scrolls to the change, but this is most of the time not what we want.

Add

VscodePosition (result of createVscodeRangeAndPosition and tsFindPositionFromContent ect), now has 'content'

0.8.13-0.8.17

Upgrade dependencies

Due to problem with upgrading fs-extra (There has been some small changes to make use it vsc worked as expected)

0.8.12

Breaking changes

Spellcheck has found some typos:

getSubrelativePathFromAbsoluteRootPath is now getSubRelativePathFromAbsoluteRootPath varifyModuleMethods is now verifyModuleMethods

0.8.11

Small breaking changes

getPackageFilePaths and getPackageDependencies now by default exclude package.json under .vscode-test

(The folder vscode create while testing extensions)

To get the original behavior, add optional 'exclude' params: '**/node_modules/**'

Add

getPackageFilePaths and getPackageDependencies now take an optional 'exclude' which is an exclude pattern for the underlying findFilePaths. It can be used to control which package.json files should be included.

0.8.10

Update docs (typings)

0.8.9

Changes

copy param 'options' is now optional (It was never meant to be required!)

Add methods

Internal: vsc-base now use direct export of sub files. (Default import of vsc should be possible, and will maybe be added in future versions)

Earlier version of vsc-base made imports of sub files manual, this was never meant to be a final solution and is now changes.

(The insert methods did exist but they was not exported before)

0.8.8

Add generic to awaitResult (default any)

0.8.7

Add

new system methods:

Changes

saveFileContent, copy, move and getReadStream now takes an optional options object.

(The options is the fs and fs-extra options for the underlaying methods)

vsc-base script docs contains the links the the doc for all underlaying method.

getFileContent now takes an optional encoding (default is utf8)

0.8.6

Breaking changes

tsMatchValue is now tsIsValue

tsMatchNode is now tsIsNode

This is to follow a common pattern where 'is' returns a boolean, and 'match' returns a node.

Small Breaking changes

createVscodeRangeAndPosition has now optional trimSpaces (default true). When ts returns pos and end from a node it includes leading and trailing space. For most transpiling we need to not have the spaces included. To enable previous behavior set trimSpaces to false.

Add

new ts methods:

new vscode methods:

Changes

tsFindNodePositionFromContent now takes an optional fromPosition (number). This is used to only match nodes from a specific point an a source.

Fixes:

tsIsValue regexp match for strings and numbers is fixed.

addSelection is now working correct

addSelectionFromRange is now working correct

0.8.5

Internal Move @types/fs-extra from devDependencies to dependencies. Other extension using vsc-base that dont use fs-extra needs the typings. (for ts building process)

0.8.4

Add ts methods

The new tsMacthIdentifier is really good for smart search and replace for type/interface/variable name.

The new tsMatchNode is a genelized method taking hasAncestor and grandchild methods. and it test is the name has an initializer used for value test, aswell as test if it has an name (identifier) used for name test.

Internal updates: All tsMatch methods now use tsMatchNode

0.8.2 + 0.8.3

All tsMatch methods (except tsMatchValue), now return the node casted as the node type.

This is because typescript/vscode did not understand the node type, so you would need to do another ts.isType for casting.

0.8.1

Fix incorrect ts interface ror tsHasChildren a tsHasGrandChildren and tsHasAncestors.

0.8.0

General

The project is soon ready for the first version.

It still need some method for system handling, but in this release new ts methods has been added for easy find, match and change ts ast three.

This means that its now easy to find a node in a ts document, either one loadet with getFileContent or the active open document with getDocumentContent.

You can use the new find and match methods in transformers (tsCreateTransformer or tsCreateRemoveNodesTransformer) or in tsFindNodePositionFromContent.

Breaking changes

tsFindNodePosition is now tsFindNodePositionFromContent

Remove TsNodeVisitorCallback type to make vscode autocomplete more readable. (When it was a ts type, the autocomplete did not show the callback interface, just the type name)

Remove TsFindNodePositionCallback type. Remove TsTransformerCallback type. Remove TsMatchVariable type. Remove TsMatchFunction type. Remove TsMatchObjectProperty type.

node params now accept undefined to make it easy to use. (avoid undefined check) (If it undefined it simply return false)

Optional 'matchName' for all the above match function now accepts a string. (On string it matches the entire name)

Added

new method ts methods:

Add optional matches for all 'Match' method has new optional match options.

0.7.0

General

This update has a lot of small changes.

It is primary done, to make the tsTranspiling work naturally with vscode.

There is now the new (tsFindNodePosition)tsFindNodePositionFromContent. This is internally an transformer with a visitor callback like the tsCreatorTranformer, but it accepts only a returned boolean.

When the callback returns true, it returns the node, and a vscode range, for where the node is in the document.

This can then be use with the new insertAtRange, to replace elements in a opne document, or simply to select the found not the the new setSelectionFromRange

The new tsVisitWithTransformers is the same as tsTransform, but its used for visitor patterns (Where there is no actual transforming)

All the methods for document with the name 'active' from vscode has remove the 'active' part, and takes document and editors instead, but they all use the default active TextDocument and active TextEditor.

There is also some new methods for executing bash command, see writeToTerminal and execFromPath

Internal changes

The document script (The scripts that generates the vsc-base.org documentation), has been updated to use more of the standard 'markdown'. (It now accepts ** for bold text and link with labels: [label](url))

Breaking changes

Interface for appendToDocument has changed from:

appendToDocument = async (
   editor: vscode.TextEditor,
   document: vscode.TextDocument
   content: string,
): Promise<void>

to

appendToDocument = async (
   content: string,
   editor?: vscode.TextEditor
): Promise<boolean>

(editor will use vsc.getActiveEditor and document vsc.getActiveDocument if undefined)

It now returns true on success or false if there was no open document or textEditor.

appendToActiveDocument is has been remove. Use appendToDocument now (It does the same)

setActiveDocumentContent is now: setDocumentContent. It can now take a textEditor is input, or it will use vsc.getActiveEditor.

  content: string,
  editor?: vscode.TextEditor,

appendLineToActiveDocument is now appendLineToDocument It can now take a textEditor is input, or it will use vsc.getActiveEditor.

  content: string,
  editor?: vscode.TextEditor,

getActiveDocumentContent is now getDocumentContent It can now take a textDocument is input, or it will use vsc.getActiveDocument.

getActiveDocumentPath is now getDocumentPath It can now take a textDocument is input, or it will use vsc.getActiveDocument.

saveActiveDocument is now saveDocument It can now take a textDocument is input, or it will use vsc.getActiveDocument.

Added

New dependency has been added to vsc: child-process-promise It can be used in vsc-script like this:

import * as cp from 'child-process-promise'

new vscode methods:

new system method:

  • execFromPath Execute a command in the nodejs context (Not vscode!)

new ts method

Changes

getActiveDocument now takes an optional 'editor' If not it uses vsc.getActiveEditor.

Release note for vsc-base 0.6.1

Breaking changes:

maxDepthReplacer has lost Optional params: 'currentLevel: number = 0' This is because it now uses the new objectWalker internally.

Added method

New method for walking and mutating objects: objectWalker

The new objectWalker method is primary a debug/logging tool.

It walks trough an object children and create a deep clone of the object.

The objectWalker is now the base for keyValueReplacer og maxDepthReplacer.

export const keyValueReplacer = (obj: unknown, key: string, newValue: any): any => {
   const walkedObj = vsc.objectWalker(obj, (state) => {
      if (state.key === key) {
         state.replace(newValue)
      }
   })
   return walkedObj
}
export const maxDepthReplacer = (obj: unknown, maxDepth: number): any => {
   const walkedObj = vsc.objectWalker(obj, (state) => {
      if (state.depth >= maxDepth) {
         state.replace(
            Array.isArray(state.ancestors[0])
               ? `[vsc: maxDepth ${maxDepth} reached - Array]`
               : `[vsc: maxDepth ${maxDepth} reached - Object]`
         )
      }
   })
   return walkedObj
}

The objectWalker take an object to walk, (Goes trough each object property/array item, and repeat this if the item is an object or array)

It applies the callback for each item (child) which is called with a state object.

The state object contains for state values for the current iteration, and a replace method for replacing the current item (child), and a stop method.

interface ObjectWalkerCallbackState {
   /**
    * The current child. (Any type)
    */
   obj: any,
   /**
    * The key for this child (a string if its in an object, a number if its in a list)
    */
   key: string | number,
   /**
    * The depth is how many step down an ancestor tree the iteration currently is in.
    */
   depth: number,
   /**
    * List with the ancestors (object or array)
    */
   ancestors: (object | Array<any>)[],
   /**
    * List with the ancestors keys (string for object, number for array item)
    */
   ancestorKeys: (string | number)[]
   /**
    * Replace the current child in parent object/array
    */
   replace: (val: any) => void,
   /**
    * Stop the recursive iteration in the walker. \ 
    * Everything stops after calling this method. \
    * The return object (which is copying itself from the original method), \
    * will only be fill with properties until the point of the stop call.
    */
   stop: () => void,
}

Release note for vsc-base 0.5.0

Breaking changes:

tsTransformSourceFile is now: tsTransformNode.

Added method

new method tsCreateNodeVisitor and type TsNodeVisitorCallback

This is almost identical to tsCreateTransformer, except it only accepts a void returment because it dont repplace any nodes.

This is used for collecting data without replacing any nodes,

It still need to be run through the vsc.tsTransform (To compile a node from the source and get the correct context like compiler options etc.)

const vscMethod = `
/**
 * @description 
 * Generate relative path between two paths.
 * @see http://vsc-base.org/#getRelativePath
 * @param fromPath
 * @param toPath
 * @vscType Raw
 * @oneLineEx const relativePath = vsc.getRelativePath(fromPath, toPath)
 * @testPrinterArgument
 { 
 fromPath: 'c:/somefolder/sub1/sub2/someFile.js',
   toPath: 'c:/somefolder/other/someFile.js'
}
* @testPrinter (args, printResult) => {
const relativePath = vsc.getRelativePath(args.fromPath, args.toPath)
printResult(relativePath)
}
* @dependencyInternal sharedPath, splitPath, subtractPath
* @returns string
*/
export const getRelativePath = (fromPath: string, toPath: string): string => {
  const _sharedPath = vsc.sharedPath(fromPath, toPath)
  const [fromDir] = vsc.splitPath(fromPath)
  const [toDir] = vsc.splitPath(toPath)
  const fromPathDownToShared = vsc.subtractPath(fromDir, _sharedPath)
  let toPathDownToShared = vsc.subtractPath(toDir, _sharedPath)
  const backPath = fromPathDownToShared
    .split(/\//)
    .map(_ => '../')
    .join('')
  const relativePath = backPath + toPathDownToShared
  return relativePath
}

`
// The data we want to collect:
const dependencyList = {
   vsc: new Set<string>(),
   ts: new Set<string>(),
   fs: new Set<string>(),
   vscode: new Set<string>(),
}
// Find all Call Expressions, test if they use any of: vsc, ts, fs or vscode
const collectDefs = vsc.tsCreateNodeVisitor((node) => {
   if (!ts.isCallExpression(node)) { // is call expression
      return
   }
   const expression = node.expression;
   const content = expression.getText();
   for (const [key, list] of Object.entries(dependencyList)) {
      const matcher = `${key}.`;
      if (content.indexOf(matcher) === 0) { // <-- Collect data is it match 
         const val = content.substr(matcher.length)
         list.add(val) // <-- Use Set to avoid duplicates
      }
   }
});
// Run transformer
vsc.tsTransform(vscMethod, [collectDefs]);
// Print result:
for (const [key, arrSet] of Object.entries(dependencyList)) {
   const arr = [...arrSet] // convert to array (from set)
   log += `${key}: (${arr.length})  ${vsc.toJSONString(arr)}\n`
}
/*
vsc: (3)  [
  "sharedPath",
  "splitPath",
  "subtractPath"
]
ts: (0)  []
fs: (0)  []
vscode: (0)  []
*/

Release note for vsc-base 0.4.0

Breaking changes:

Ts methods has been rename. Most important is loadTsModule which is now tsLoadModule.

For internal code All methods that uses ts api is now moved to their own file in the base of the project (Note: All development of vsc-base is done in vsc-script project! )

Add new method for using ts api

vsc-base now has tsTransform which takes a string (typescript code) and transform it to a new string (typescript code). It tsTransform uses transformers created with tsCreateTransformer and tsCreateRemoveNodesTransformer:

const updateCode = vsc.tsTransform(code, [transformer1, transformer2])

This enable precise and good ways to transform code (instead of using RegExp).